2012-04-06 63 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