点击按钮后创建一个100px,背景银灰色的div,内容是HTML DOM练习
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> newdocument </title>
<meta name="generator"content="editplus" />
<metaname="author" content="" />
<metaname="keywords" content="" />
<metaname="description" content="" />
<script>
function creatdiv(){
var div=document.createElement("div");
div.style.backgroundColor="silver";
div.style.fontSize="100px";
div.innerHTML="HTML DOM练习";
div.setAttribute("id","div2");
document.getElementById("div1").appendChild(div);
}
functionremovediv(){
var del=document.getElementById("div1");
varn_div=document.getElementById("div2");
del.removeChild(n_div);
}
</script>
</head>
<body>
<divid="div1"></div>
<inputtype="button" value="创建" οnclick="creatdiv()">
<inputtype="button" value="删除" οnclick="removediv()">
</body>
</html>