JS動態添加刪除控件

在TABLE裏實現的代碼:
Function Add() //添加控件
{
var nRow=document.all.Table1.rows.length; //獲得當前TABLE的行數
var objTheRow=document.all.Table1.insertRow(nRow);//執行添加
objTheRow.insertCell(0);//添加當前行的列
//添加一個按紐控件
objTheRow.cells(0).innerHTML="<input type='button' value='delete me'onclick='Delete()'>";
}

Function Delete() //刪除控件
{
var currRowIndex=event.srcElement.parentNode.parentNode.rowIndex;//獲取當前索引
document.all.Table1.deleteRow(currRowIndex);//執行刪除
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章