"JQuery 테이블 비우기"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(사용자 3명의 중간 판 5개는 보이지 않습니다)
3번째 줄: 3번째 줄:


==예시 1: 전체 비우기==
==예시 1: 전체 비우기==
<source lang='html5'>
<syntaxhighlight lang='html5'>
<script src="//code.jquery.com/jquery.min.js"></script>
<script src="//code.jquery.com/jquery.min.js"></script>
<script>
<script>
$(function () {
$(function () {
     $('#btn-empty').click( function() {
     $('#btn-delete').click( function() {
         $( '#mytable').empty();
         $( '#mytable').delete();
     });
     });
});
});
</script>
</script>


<button id='btn-empty'>테이블 비우기</button>
<button id='btn-delete'>테이블 비우기</button>
<hr>
<hr>


<tableborder="1" cellspacing="0">
<table id="mytable" border="1" cellspacing="0">
     <tr>
     <tr>
         <th>컬럼1</th><th>컬럼2</th>
         <th>컬럼1</th><th>컬럼2</th>
     </tr>
     </tr>
     <tbody id="mytable" >
     <tbody>
         <tr><td>1</td><td>한놈</td></tr>
         <tr><td>1</td><td>한놈</td></tr>
         <tr><td>2</td><td>두시기</td></tr>
         <tr><td>2</td><td>두시기</td></tr>
26번째 줄: 26번째 줄:
     </tbody>
     </tbody>
</table>
</table>
</source>
</syntaxhighlight>
<jsfiddle height='200'>d2hwq5y6</jsfiddle>
<jsfiddle height='200'>d2hwq5y6</jsfiddle>


==예시 2: 헤더 제외하고 비우기==
==예시 2: 헤더 제외하고 비우기==
<source lang='html5'>
<syntaxhighlight lang='html5'>
<script src="//code.jquery.com/jquery.min.js"></script>
<script src="//code.jquery.com/jquery.min.js"></script>
<script>
<script>
44번째 줄: 44번째 줄:


<table id="mytable" border="1" cellspacing="0">
<table id="mytable" border="1" cellspacing="0">
     <tr>
     <thead>
         <th>컬럼1</th><th>컬럼2</th>
         <th>컬럼1</th><th>컬럼2</th>
     </tr>
     </thead>
     <tbody>
     <tbody>
         <tr><td>1</td><td>한놈</td></tr>
         <tr><td>1</td><td>한놈</td></tr>
53번째 줄: 53번째 줄:
     </tbody>
     </tbody>
</table>
</table>
</source>
</syntaxhighlight>
<jsfiddle height='200'>ea6mL08v</jsfiddle>
<jsfiddle height='200'>ea6mL08v</jsfiddle>


61번째 줄: 61번째 줄:
*[[HTML table 태그]]
*[[HTML table 태그]]


==참고 자료==
==참고==
*http://stackoverflow.com/questions/2620181/clear-table-jquery
*http://stackoverflow.com/questions/2620181/clear-table-jquery


[[분류: jQuery]]
[[분류: jQuery]]
[[분류: jsFiddle]]
[[분류: jsFiddle]]

2020년 11월 2일 (월) 02:53 기준 최신판

jQuery 테이블 비우기

1 예시 1: 전체 비우기[ | ]

<script src="//code.jquery.com/jquery.min.js"></script>
<script>
$(function () {
    $('#btn-delete').click( function() {
        $( '#mytable').delete();
    });
});
</script>

<button id='btn-delete'>테이블 비우기</button>
<hr>

<table id="mytable" border="1" cellspacing="0">
    <tr>
        <th>컬럼1</th><th>컬럼2</th>
    </tr>
    <tbody>
        <tr><td>1</td><td>한놈</td></tr>
        <tr><td>2</td><td>두시기</td></tr>
        <tr><td>3</td><td>석삼</td></tr>
    </tbody>
</table>

2 예시 2: 헤더 제외하고 비우기[ | ]

<script src="//code.jquery.com/jquery.min.js"></script>
<script>
$(function () {
    $('#btn-empty').click( function() {
        $( '#mytable > tbody').empty();
    });
});
</script>

<button id='btn-empty'>테이블 비우기</button>
<hr>

<table id="mytable" border="1" cellspacing="0">
    <thead>
        <th>컬럼1</th><th>컬럼2</th>
    </thead>
    <tbody>
        <tr><td>1</td><td>한놈</td></tr>
        <tr><td>2</td><td>두시기</td></tr>
        <tr><td>3</td><td>석삼</td></tr>
    </tbody>
</table>

3 같이 보기[ | ]

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}