2012-04-06 61 views
0

我創建了側一排動態刪除最後一個動態生成HTML行創建的jQuery

var index = 1; 

$("#add_field").click(function(){ 

var new_field = '<tr><th style="text-align: left;">Customer '+index+'</th><td><input type="text" id="customer'+index+'" name="customer'+index+'" maxlength="50"></td><th style="text-align: left;">Phone</th><td><input type="text" id="customerphone'+index+'" name="customerphone'+index+'" maxlength="14"></td><th style="text-align: left;">Email</th><td><input type="text" id="customeremail'+index+'" name="customeremail'+index+'" maxlength="100"></td></tr>'; 

$("#customerFormTable").append(new_field); }); 

HTML

<div id="add_field">Click here to add more rows </div> 

我現在該如何建立一個刪除表 - 刪除最後一行我剛剛創建

<div id="delete_row">Click here to delete last row created </div> 

$("#delete_row").click(function(){ ?????? 

回答

2
$("#customerFormTable tr:last").remove(); 
0

給ID來埃爾基於TREM刪除該特定行

$("#trid").remove(); 
+0

謝謝你的答案。他們幫我完成了。這裏是我寫的 首先,當我創建了TR動態我給它的ID 那麼對於刪除 $( 「#remove_field」)。點擊(function(){ \t index--; \t $(「#new」+ index).remove(); }); 所有的作品完全如我所願,謝謝。 – user1253239 2012-04-06 12:25:31