当前位置 : 主页 > 手机开发 > harmonyos >

表格操作二例

来源:互联网 收集:自由互联 发布时间:2023-10-08
例一: 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>

上一篇:JScript中prototype属性应用讲解
下一篇:没有了
网友评论