标签:style blog color io ar div cti html log
功能实现:点击添加按钮,表格增加一行并给其name属性赋予的值,方便获取
点击删除,自动删除这一行
JQuery中定义一个count变量
1 var count = 1; 2 function add() { 3 var tbl = document.all.ci; 4 var rows = tbl.rows.length; 5 var tr = tbl.insertRow(rows); 6 7 var e_id = tr.insertCell(0); 8 e_id.innerHTML = ‘<input type="text" name="e_id‘ + count + ‘" size="7" />‘; 9 10 var class_id = tr.insertCell(1); 11 class_id.innerHTML = ‘‘; 12 13 var memo = tr.insertCell(2); 14 memo.innerHTML = ‘<input type="text" name="memo‘ + count + ‘" size="14" />‘; 15 16 var del = tr.insertCell(3); 17 del.innerHTML = ‘<input type="button" onclick="del(this)" value="删除" />‘; 18 count++; 19 } 20 21 function del(btn) { 22 var tr = btn.parentElement.parentElement; 23 var tbl = tr.parentElement; 24 if (tr.rowIndex >= 1) { 25 tbl.deleteRow(tr.rowIndex); 26 } else { 27 28 } 29 };
标签:style blog color io ar div cti html log
原文地址:http://www.cnblogs.com/stayreal/p/3931548.html