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

 
(사용자 4명의 중간 판 14개는 보이지 않습니다)
4번째 줄: 4번째 줄:


==예시==
==예시==
<source lang='html'>
<syntaxhighlight lang='html' run outheight='250'>
<style>
thead { background-color: skyblue; }
</style>
 
<button id='btn-add-row'>행 추가하기</button>
<button id='btn-add-row'>행 추가하기</button>
<button id='btn-delete-row'>행 삭제하기</button>
<button id='btn-delete-row'>행 삭제하기</button>
10번째 줄: 14번째 줄:


<table id="mytable" border="1" cellspacing="0">
<table id="mytable" border="1" cellspacing="0">
   <tr>
   <thead>
    <th>제목</th>
    <tr>
    <th>일시</th>
      <th>ITEM</th>
   </tr>
      <th>DATETIME</th>
    </tr>
   </thead>
   <tbody></tbody>
   <tbody></tbody>
</table>
</table>
21번째 줄: 27번째 줄:
   $('#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 rowspan=3>안녕ㅋ 친구들ㅋ </td><td>' + time + '</td></tr>');
     $('#mytable > tbody:last').append('<tr><td>HELLO world</td><td>' + time + '</td></tr>');
   });
   });
   $('#btn-delete-row').click(function() {
   $('#btn-delete-row').click(function() {
     $('#mytable > tbody').remove();
     $('#mytable > tbody > tr:last').remove();
   });
   });
</script>
</script>
</source>
</syntaxhighlight>
<jsfiddle height='250'>jmnote/4pgfgvkx</jsfiddle>


==같이 보기==
==같이 보기==

2021년 5월 24일 (월) 20:51 기준 최신판

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

1 예시[ | ]

<style>
thead { background-color: skyblue; }
</style>

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

<table id="mytable" border="1" cellspacing="0">
  <thead>
    <tr>
      <th>ITEM</th>
      <th>DATETIME</th>
    </tr>
  </thead>
  <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>HELLO world</td><td>' + time + '</td></tr>');
  });
  $('#btn-delete-row').click(function() {
    $('#mytable > tbody > tr:last').remove();
  });
</script>

2 같이 보기[ | ]

3 참고[ | ]

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