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

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
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>
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>
53번째 줄: 53번째 줄:
     </tbody>
     </tbody>
</table>
</table>
</source>
</syntaxhighlight>
<jsfiddle height='200'>ea6mL08v</jsfiddle>
<jsfiddle height='200'>ea6mL08v</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 }}