点击增加删除文本框

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<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 = '<textarea type="text" />';
contentCell = newRow.insertCell(-1);

var delBtn = document.createElement("input");
delBtn.type = "button";
delBtn.className = "button";
delBtn.id = "btnDel"+count;
delBtn.value = "删除";
delBtn.onclick = new Function("del(this)");
contentCell.appendChild(delBtn);

count++;
}

function del(obj) {
var row = obj.parentNode.parentNode;
row.parentNode.removeChild(row);
}
</script>
<style>
textarea{width:300px;height:100px;}
</style>
</head>
<body>
<fieldset>
<legend>
insertRow新增
</legend>
<input type="button" class="button" value="新增" onclick="addByScript()"/>
<table id="tbl1">
</table>
</fieldset>
</body>
</html>

posted @ 2017-11-23 16:11  孙阳君  阅读(198)  评论(1编辑  收藏  举报