Home >Web Front-end >Front-end Q&A >How to delete controls in javascript

How to delete controls in javascript

藏色散人
藏色散人Original
2021-10-20 14:13:181861browse

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.

How to delete controls in javascript

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=&#39;button&#39; value=&#39;delete me&#39;οnclick=&#39;Delete()&#39;>";
}
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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn