日期:2014-05-17 浏览次数:20781 次
script type="text/javascript"> function delRow(obj) { $("#tab tr).last().remove();//从下往上删除行 $("#tab tr).first().remove();//从上往下删除行 } </script> </head> <body> <!-- <table border="1" id="tab"> <tr id="n1"><td>删除我啊1</td><td><input type="button" value="删除" onclick="delRow(this)"/></td></tr> <tr id="n2"><td>删除我啊2</td><td><input type="button" value="删除" onclick="delRow(this)"/></td></tr> <tr id="n3"><td>删除我啊3</td><td><input type="button" value="删除" onclick="delRow(this)"/></td></tr> </table> --> <table border="1" id="tab"> <tr id="n1"><td>删除我啊1</td><td>删除我啊1</td></tr> <tr id="n2"><td>删除我啊2</td><td>删除我啊2</td></tr> <tr id="n3"><td>删除我啊3</td><td>删除我啊3</td></tr> </table> <input type="button" value="删除" onclick="delRow()"/>
------解决方案--------------------
我自己用的方法,你可以参考下:
function deleteRow(r) { var i=r.parentNode.parentNode.rowIndex; document.getElementById('myTable').deleteRow(i); var countline = document.getElementById('countline').value - 1; var x1=document.getElementById('countline').value=countline; } function insRow() { var countAll = document.getElementById('countAll').value - 1+2; var countline = document.getElementById('countline').value -1 +2; var x=document.getElementById('myTable').insertRow(countline); var y=x.insertCell(0); var y1=x.insertCell(1); var y2=x.insertCell(2); y.innerHTML="<textarea id='aa"+countAll+"' name='bb"+countAll+"' style='width:97%;' rows='2' ></textarea>"; y1.innerHTML="<select id='cc"+countAll+"' name='dd"+countAll+"' style='width:98%;'><option value=''></option></select>"; y2.innerHTML="<textarea id='ee"+countAll+"' name='ff"+countAll+"' style='width:97%;' rows='2' ></textarea>"; var x1=document.getElementById('countline').value=countline; var x2=document.getElementById('countAll').value=countAll; }