ถามเรื่องลบ แถวออกจากตารางด้วย jQuery

จากโค๊ดนี้อะค่ะ มันมีทั้งโค๊ด เพิ่มและ ลบ ค่ะ 
ตอนนี้มันเพิ่มแถวได้ตามที่เรากดปุ่มเพิ่มอะค่ะ

แต่ตอนลบมันลบได้แค่แถวเดียว  ช่วยดูให้หน่อยค่ะ 


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<title>Add row to table</title>
<script type="text/javascript">
$(document).ready(function(){
 
 $('#button2').click(function(){
       
  var th = $('<tr ><th id="th"><input type=\"text\" name=\"n[]\" /></th><th><input type=\"text\" name=\"a[]\" /></th><th><input type=\"text\" name=\"m[]\" /></th><th><input type=\"text\" name=\"e[]\" /></th><th><input type=\"text\" name=\"s[]\" /></th></tr>');
  $('#table').append(th);
 
 });

   $('#button1').click(function(){
     var th = $('<tr ><th id="th"><input type=\"text\" name=\"n[]\" /></th><th><input type=\"text\" name=\"a[]\" /></th><th><input type=\"text\" name=\"m[]\" /></th><th><input type=\"text\" name=\"e[]\" /></th><th><input type=\"text\" name=\"s[]\" /></th></tr>');

    $('#th').parent().hide();
   });
 
})
</script>
</head>
<body>
<input type="button" name="button2" id="button2" value="เพิ่มแถว" />
<input type="button" name="button1" id="button1" value="ลบ" />
<br />
<form id="form" name="form" method="post" action="tt2.php">
  <table width="482" id="table">
    <tr>
      <th width="87">ลำดับ</th>
      <th width="152">สาขา</th>
      <th>ลำดับ</th>
      <th>สาขา</th>
      <th width="18">สาขา</th>
    </tr>
    <tr>
     <th id="th"><input name="n[]" type="text" id="n[]" size="20"  /></th>
      <th><input name="a[]" type="text" id="a[]" size="10"  /></th>
      <th><input name="m[]" type="text" id="m[]" size="10"  /></th>
      <th><input name="e[]" type="text" id="e[]" size="10" /></th>
      <th><input name="s[]" type="text" id="s[]" size="10" /></th>
    </tr>
   
  </table>
 

15 มี.ค. 2553 0 2,698
ยังไม่มีความคิดเห็น โพสต์เลยตอนนี้
ความคิดเห็น
ไฟล์อัปโหลด ชนิด jpg, jpeg ขนาดไฟล์ไม่เกิน 1024
^