<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
/*
创建节点,插入节点,设置节点属性。
创建节点: document.createElement(Tagname)
设置节点属性; elt.setAttribute("属性名",属性值);
添加元素到elt最后的位置 elt.appendChild(e);
插入目标元素的位置:
elt.insertBefore(new,child) 参数1,要插入的节点。
elt.removeChild(child) 删除指定的节点
*/
var num=1;
function add(){
var addNode=document.createElement("input");
addNode.setAttribute("type","button");
addNode.setAttribute("value","按钮"+num);
var bodyNode=document.getElementsByTagName("body")[0];
bodyNode.appendChild(addNode);
num++;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>创建节点和插入节点</title>
</head>
<body>
<input type="button" value="添加" οnclick="add()"/>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
/*
创建节点,插入节点,设置节点属性。
创建节点: document.createElement(Tagname)
设置节点属性; elt.setAttribute("属性名",属性值);
添加元素到elt最后的位置 elt.appendChild(e);
插入目标元素的位置:
elt.insertBefore(new,child) 参数1,要插入的节点。
elt.removeChild(child) 删除指定的节点
*/
var num=1;
function add(){
var addNode=document.createElement("input");
addNode.setAttribute("type","button");
addNode.setAttribute("value","按钮"+num);
var bodyNode=document.getElementsByTagName("body")[0];
bodyNode.appendChild(addNode);
num++;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>创建节点和插入节点</title>
</head>
<body>
<input type="button" value="添加" οnclick="add()"/>
</body>
</html>