<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>layer js</title>
</head>
<body>
<div>
<div>
<img src="static/images/bg.png" alt="">
<input type="button"onclick="mm()" id="btn" />
</div>
<div></div>
</div>
</body>
<script type="text/javascript">
window.onload=function(){
var btn=document.getElementById("btn");
function mm()
{
var sHeight=document.documentElement.scrollHeight;
var sWidth=document.documentElement.scrollWidth;
var mask=document.createElement("div");
mask.id="omask";
mask.style.height=sHeight+"px";
mask.style.width=sWidth+"px";
document.body.appendChild(mask);
var oimg=document.createElement("div");
oimg.id="img";
oimg.innerHTML="<img src='static/images/bg.png' alt='' />";
document.body.appendChild(oimg)
alert("sssss")
}
}
</script>
</html>
为什么我把mm函数写在window.onload里,点击按钮会报错。说mm()没定义呢,去掉window.onload就好了
stone310