Javascript method to delete a control: 1. Get the number of rows in the current TABLE; 2. Add the columns of the current row; 3. Add a button control; 4. Through "Function Delete(){...} "Just delete the control.
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
How to delete a control using JavaScript?
JS dynamically add and delete controls
Code implemented in 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'οnclick='Delete()'>"; } Function Delete() //删除控件 { var currRowIndex=event.srcElement.parentNode.parentNode.rowIndex;//获取当前索引 document.all.Table1.deleteRow(currRowIndex);//执行删除 }
Recommended learning: "javascript basic tutorial"
The above is the detailed content of How to delete controls in javascript. For more information, please follow other related articles on the PHP Chinese website!