<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>测试代码</title>
<script type="text/javascript">
function a(){
var body = document.body;
var table = document.createElement("table");
body.appendChild(table);
table.setAttribute("border","1");
table.setAttribute("width","50%");
table.setAttribute("id","table");
var input = document.createElement("input");
input.setAttribute("type","button");
input.setAttribute("value","填写信息");
input.setAttribute("onclick","add1()");
body.appendChild(input);
}
function add1(){
var table = document.getElementsByTagName("table");
var tr = document.createElement("tr");
// table.appendChild(tr);
for (var i=1;i<=4;i++){
var td = document.createElement("td");
td.innerHTML = "<input type='text'>";
tr.appendChild(td);
}
table.appendChild(tr);
}
</script>
</head>
<body>
<input type="button" value="添加" onclick="a()"/>
</body>
</html>
李晓健
相关分类