JS动态添加删除表格数据
<!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="删除" onclick="del(\‘‘+trId+‘\‘)">‘; } function del(trId) { var tableObject=document.getElementById("stuTable"); var tableRowObject=document.getElementById(trId); tableObject.deleteRow(tableRowObject.rowIndex); }</script><input type="text" id="stuName"><input type="button" value="添加" onclick="change()"><table border="3px" id="stuTable"> <tr> <th>姓名</th> <th>操作</th> </tr></table></body></html>
相关推荐
阿斌Elements 2020-06-11
zrtlin 2020-11-09
xuebingnan 2020-11-05
wikiwater 2020-10-27
heheeheh 2020-10-19
Crazyshark 2020-09-15
softwear 2020-08-21
ZGCdemo 2020-08-16
jczwilliam 2020-08-16
littleFatty 2020-08-16
idning 2020-08-03
jinxiutong 2020-07-26
lanzhusiyu 2020-07-19
Skyline 2020-07-04
xiaofanguan 2020-06-25
Aveiox 2020-06-23