当前位置:首页 > Web开发 > 正文

标签: !DOCTYPE html html lang="en" head meta charset="UTF-8"

2024-03-31 Web开发

标签:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JSDom获取图层节点</title>
</head>
<body>
<script type="text/javascript">
function change() {
var stuName=document.getElementById("stuName").value;
var stuTable=document.getElementById("stuTable");
var index=stuTable.rows.length;
var tableRowObj=stuTable.insertRow(index);
var trId="table"+index;
tableRowObj.id=trId;
var tableCell0=tableRowObj.insertCell(0);
var tableCell1=tableRowObj.insertCell(1);
tableCell0.innerHTML=stuName;
tableCell1.innerHTML=‘<input type="button" value="删除">‘;
}
function del(trId) {
var tableObject=document.getElementById("stuTable");
var tableRowObject=document.getElementById(trId);
tableObject.deleteRow(tableRowObject.rowIndex);

}
</script>
<input type="text">
<input type="button" value="添加">
<table>
<tr>
<th>姓名</th>
<th>操纵</th>
</tr>
</table>
</body>
</html>

技术图片

JS动态添加删除表格数据

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/32754.html