javascript动态添加删除表格及克隆表格

insertRow()和deleteRow()方法:
add
del
test

<script language="JavaScript">
var n=0;
function add(){
n++;
t1.insertRow().insertCell().innerHTML = 'delthis';
//t1.insertRow().insertCell().innerHTML = '';
}
function del(){
var c = document.getElementsByName('tt');
for(var i=0; i<c.length; i++)<br="">if(c[i].checked)
t1.deleteRow(i);
}
function deleteRow(obj){
t1.deleteRow(obj.parentElement.parentElement.rowIndex);
}
function test(){
for(i=0;i<t1.rows.length;i++) alert(t1.rows[i].cells[0].innerhtml);<br="">}
</script>

cloneNode()方法克隆表格:


<script language="JavaScript">
i=1
function add(){
++i;
var newTR = a1.cloneNode(true);
newTR.id="a"+i;
newTR.name="a"+i;
a1.parentNode.insertAdjacentElement("beforeEnd",newTR);
//alert(a1.parentElement.innerHTML);
}
</script>

appendChild() & removeChild()方法:(firefox only)
1234

append +remove -
 

 

你可能感兴趣的:(JavaScript,C++,c,C#,firefox)