最近做到循环添加的功能,希望点击按钮可以自动为table表格增加一行,两种实现方式:
if(name == '添加'){
document.getElementById("opera").value = 'add';
document.form_search.submit();
}else if(name == '继续添加'){
第一种:
var row = document.getElementById("rowToclone"); // find row to copy
var table = document.getElementById("add_table"); // find table to append to
var clone = row.cloneNode(true); // copy children too
var cc = $("#classify").val();
clone.id = cc; // change id or other attributes/contents
table.appendChild(clone);
第二种:
var row = $('#add_table tbody>tr:last').clone(true);
$("td input:text",row).val("");
row.insertAfter('#add_table tbody>tr:last');
return false;
}
不过第一种复制的时候会将目标行的数据也一块儿带过来,第二种不会