Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https: //blog.csdn.net/feng_cs/article/details/2966402
dynamically add a line, or delete the specified line.
Use the HTML DOM object.
Mainly insertRow (), insertCell (), deleteRow () method is used.
<HTML>
<head>
<title> addrow.html </ title>
<Script type = "text / JavaScript">
var = NUM. 1;
function addRow () {
var TB = document.getElementById ( "mytableid");
var Row tb.insertRow = ();
var = row.insertCell Cell ();
cell.innerText = "first" + num + "OK";
NUM ++;
Cell row.insertCell = ();
cell.innerHTML = "<input type='text' value = '新一行'>";
}
function delRow() {
var rowIndex = document.getElementById("delTextId").value;
var tb = document.getElementById("mytableid");
tb.deleteRow(rowIndex-1);
}
</script>
</head>
<body>
<table id="mytableid">
<!-- <tr><td>第一行</td><td>输入</td></tr> -->
</table>
<input type="button" value="新增一行" οnclick="addRow()" />
<br>
<input type="text" id="delTextId" />
<input type="button" value="删除选择行" οnclick="delRow()" />
</body>
</html>
Dynamic HTML increasing realization delete rows
Guess you like
Origin blog.csdn.net/weixin_41926640/article/details/100155293
Recommended
Ranking