关于document.body.insertAdjacentElement问题,麻烦帮忙解答下
我每点一次button 就会插入一个 "aaa " 可以怎么判断一下,来解决这个问题,麻烦大家了
==================代码=================
<html>
<head>
<script language= "javascript ">
function pushbutton(){
var div = document.createElement( "div ");
div.innerHTML = "aaa ";//改变内部代码。
document.body.insertAdjacentElement( "beforeEnd ", div);
}
</script>
</head>
<body>
<form>
<input type= "button " name= "Button1 " value= "Pushme " onclick= "pushbutton() ">
</form>
</body>
</html>
------解决方案--------------------function pushbutton()
{
if(document.getElementById( "mzDiv ")) return;
var div = document.createElement( "div ");
div.innerHTML = "aaa ";//改变内部代码。
div.id = "mzDiv ";
document.body.appendChild(div);
}