
Asp按钮操作网页上表格增加一空行或删除一空行,怎么写?
2个回答
展开全部
<html>
<head>
<script>
var count = 0;
function addByScript() {
var table = document.getElementById("tbl1");
var newRow = table.insertRow(table.rows.length);
newRow.id = "row" + count;
var contentCell = newRow.insertCell(-1);
contentCell.innerHTML = '<table width=100% border=1><tr><td>11111</td></tr></table>';
contentCell = newRow.insertCell(-1);
var delBtn = document.createElement("input");
delBtn.type = "button";
delBtn.className = "button";
delBtn.id = "btnDel"+count;
delBtn.value = "del";
delBtn.onclick = new Function("del(this)");
contentCell.appendChild(delBtn);
count++;
}
function del(obj) {
var row = obj.parentNode.parentNode;
row.parentNode.removeChild(row);
}
</script>
</head>
<body>
<fieldset>
<input type="button" class="button" value="add" onclick="addByScript()"/>
<table id="tbl1">
</table>
</fieldset>
</body>
</html>
<head>
<script>
var count = 0;
function addByScript() {
var table = document.getElementById("tbl1");
var newRow = table.insertRow(table.rows.length);
newRow.id = "row" + count;
var contentCell = newRow.insertCell(-1);
contentCell.innerHTML = '<table width=100% border=1><tr><td>11111</td></tr></table>';
contentCell = newRow.insertCell(-1);
var delBtn = document.createElement("input");
delBtn.type = "button";
delBtn.className = "button";
delBtn.id = "btnDel"+count;
delBtn.value = "del";
delBtn.onclick = new Function("del(this)");
contentCell.appendChild(delBtn);
count++;
}
function del(obj) {
var row = obj.parentNode.parentNode;
row.parentNode.removeChild(row);
}
</script>
</head>
<body>
<fieldset>
<input type="button" class="button" value="add" onclick="addByScript()"/>
<table id="tbl1">
</table>
</fieldset>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询