日期:2014-05-17 浏览次数:20841 次
<HTML>
<TITLE>Form Object example</TITLE>
<HEAD>
<script language="javascript">
function delrow1()
{
var oElement=event.srcElement;
while(oElement.tagName!="TR")
{
oElement=oElement.parentElement;
}
var oTBody=oElement.parentElement;
oTBody.removeChild(oElement)
}
function delrow2()//刪除当前行
{
var currRowIndex=event.srcElement.parentNode.parentNode.rowIndex;
document.all.yltable.deleteRow(currRowIndex);//table10--表格id
}
function insertrow1() //增加的一行方法1
{
var newnode = document.getElementById('yltable').lastChild.cloneNode(true);
document.getElementById('yltable').appendChild(newnode);
}
function insertrow2() //增加的一行方法2
{
newRow=document.all.yltable.insertRow(-1);
var j_1 = document.all.yltable.rows.length;
newcell=newRow.insertCell();
newRow.bgColor='#FFFFFF';
newcell.align='center';
newcell.innerHTML=""+j_1+"";
newcell=newRow.insertCell() ;
newRow.bgColor='#FFFFFF';
newcell.align='center';
newcell.innerHTML="<input type='text' name='ylText"+j_1+"' />";
newcell=newRow.insertCell() ;
newRow.bgColor='#FFFFFF';
newcell.align='center';
newcell.innerHTML='<input name="button3" type="button" onClick="delrow1()" value="删除1"> <input name="button3" type="button" onClick="delrow2()" value="删除2">';
document.all.yltable.focus();
}
function inserttable()
{
var newnode = document.getElementById('yltable').cloneNode(true);
document.getElementById('ylform').appendChild(newnode);
}
</script>
</HEAD>
<BODY>
<form name="ylform" id="ylform">
<center>
<input name="button" type="button" onClick="inserttable()" value="增加表格">
<input name="button2" type="button" onClick="insertrow1()" value="增加一行1">
<input name="button22" type="button" onClick="insertrow2()" value="增加一行2">
</center>
<table border="1" align="center" width="50%" id="yltable">
<TBODY id=yl1>