js创建元素(节点)示例
人气:0复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jquery2</title>
<script type="text/javascript">
//创建节点
var addItems = function() {
document.getElementById("div1").innerHTML = "";
var value = parseInt(document.getElementById('itemsNumber').value);
for (var i = 0; i < value; i++) {
var input = document.createElement("input");
input.setAttribute("type", "text");
var br = document.createElement("br");
document.getElementById("div1").appendChild(input);
document.getElementById("div1").appendChild(br);
}
}
</script>
</head>
<body>
<input type="text" id="itemsNumber">
<input type="button" id="btn" value="click" onclick="addItems();" >
<div id="div1"></div>
</body>
</html>
加载全部内容