例一: BODYSCRIPT LANGUAGE="JavaScript"function addRow(tbl){var a = tbl.insertRow();a.id = "a" + tbl.rows.length;for(var i=0; itbl.rows[0].cells.length; i++){var tc = a.insertCell();tc.innerText = " ";tc.onfocus = function(){this.parentE
例一:
<BODY>
<SCRIPT LANGUAGE="JavaScript">
function addRow(tbl)
{
var a = tbl.insertRow();
a.id = "a" + tbl.rows.length;
for(var i=0; i<tbl.rows[0].cells.length; i++)
{
var tc = a.insertCell();
tc.innerText = " ";
tc.onfocus = function()
{
this.parentElement.parentElement.parentElement.ct = this.parentElement;
this.innerHTML = "<input type=/"text/" value=/"" + (this.innerText==" "?"":this.innerText) + "/" style=/"width:100%;height:100%;border:0;/" οnblur=/"this.parentElement.innerText=(this.value==''?' ':this.value);/">";
this.children[0].focus();
};
}
}
function delRow(tbl)
{
if(!tbl.ct) return;
tbl.deleteRow(tbl.ct.rowIndex);
tbl.ct = null;
}
</SCRIPT>
<table border=1 id="tbl">
<tr id=a1>
<td>northsnow</td>
<td>塞北的雪</td>
</tr>
</table>
<input type="button" value="添加行" οnclick="addRow(document.all.tbl);">
<input type="button" value="删除行" οnclick="delRow(document.all.tbl);">
</BODY>
例二:
<table border=1>
<tr id=a1>
<td><input id=text1 name=text1 value="northsnow"></td><td><input id=text2 name=text2 value=塞北的雪></td>
</tr>
</table>
<input type=button name=ok value="add row" οnclick=add()>
<script language=JavaScript>
i=1
function add(){
var newTR = a1.cloneNode(true);
newTR.id="a"+(++i)
a1.parentNode.insertAdjacentElement("beforeEnd",newTR);
}
</script><script language="JavaScript" type="text/javascript"> i=1 function add(){ var newTR = a1.cloneNode(true); newTR.id="a"+(++i) a1.parentNode.insertAdjacentElement("beforeEnd",newTR); } </script>