"JQuery 테이블 행 추가/삭제"의 두 판 사이의 차이

24번째 줄: 24번째 줄:
   });
   });
   $('#btn-delete-row').click(function() {
   $('#btn-delete-row').click(function() {
     $('#mytable > tbody:last > tㅗ:last').remove();
     $('#mytable > tbody').remove();
   });
   });
</script>
</script>

2020년 3월 13일 (금) 16:23 판

jQuery 테이블 행 추가·삭제
jQuery tr 추가/삭제

1 예시

<button id='btn-add-row'>행 추가하기</button>
<button id='btn-delete-row'>행 삭제하기</button>
<hr>

<table id="mytable" border="1" cellspacing="0">
  <tr>
    <th>제목</th>
    <th>일시</th>
  </tr>
  <tbody></tbody>
</table>

<script src="//code.jquery.com/jquery.min.js"></script>
<script>
  $('#btn-add-row').click(function() {
    var time = new Date().toLocaleTimeString();
    $('#mytable > tbody:last').append('<tr ><td rowspan=3>안녕ㅋ 친구들ㅋ </td><td>' + time + '</td></tr>');
  });
  $('#btn-delete-row').click(function() {
    $('#mytable > tbody').remove();
  });
</script>

2 같이 보기

3 참고

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