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

잔글 (121.138.83.22(토론)의 편집을 Jmnote의 마지막 판으로 되돌림)
21번째 줄: 21번째 줄:
   $('#btn-add-row').click(function() {
   $('#btn-add-row').click(function() {
     var time = new Date().toLocaleTimeString();
     var time = new Date().toLocaleTimeString();
     $('#mytable > tbody:last').append('<tr><td>안녕 친구들 </td><td>' + time + '</td></tr>');
     $('#mytable > tbody:last').append('<tr><th>안녕 친구들 </th><td>' + time + '</td></tr>');
   });
   });
   $('#btn-delete-row').click(function() {
   $('#btn-delete-row').click(function() {

2018년 11월 16일 (금) 21:07 판

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

1 예시

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

<table id="mytable" border="1" cellspacing="3">
  <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><th>안녕 친구들 </th><td>' + time + '</td></tr>');
  });
  $('#btn-delete-row').click(function() {
    $('#mytable > tbody:last > tr:last').remove();
  });
</script>

2 같이 보기

3 참고

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