0

以下のコードを使用して、ボタンをクリックしてテーブルの行を追加しています。次に、新しく作成された行を削除するための別のボタンが必要です。これをするのを手伝ってください。ありがとうございました

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js">      </script>

<script>
jQuery(function(){
var counter = 1;
jQuery('input.add_row').click(function(event){
    event.preventDefault();
    counter++;
    var newRow = jQuery('<tr><td><select name="level' + counter + '"><option value="Matric or equivalent">Matric or equivalent</option><option value="10+2 or equivalent">10+2 or equivalent</option><option value="Diploma after matric">Diploma after matric</option><option value="Bachelor Degree">Bachelor Degree</option><option value="Master Degree">Master Degree</option><option value="Others">Others</option></select></td><td><input type="text" name="prog' +
        counter + '"/></td><td><input type="text" name="ins' +
        counter + '"/></td><td><input type="text" name="univ' +
        counter + '"/></td><td><input type="text" name="reg' +
        counter + '"/></td><td><input type="text" name="yr' +
        counter + '" size="4" maxlength="4"/></td><td><input type="text" name="mar' + 
        counter + '"/></td><td><input type="text" name="sub' + 
        counter + '" size="8"/></td></tr>');
    jQuery('table.aca_inf').append(newRow);
});
});
</script>
4

2 に答える 2

2

試す:

jQuery('input.del_row').click(function(event){
    event.preventDefault();
    jQuery('table.aca_inf tr:last').remove();

});
于 2013-03-08T09:09:28.113 に答える
1

使用する:

   function delete_row(){
   //delete last row of table
     while(counter){ 
     $('#btn').on("click", function (){
           $('#tab1 tr:last').remove();
           counter--;
     });
    }
  }
于 2013-03-08T09:10:25.307 に答える