预期结果为:
点击click 定时弹出一个框 , 并且有个灰色的罩子罩住页面, 防止点击弹出框以外的内容,
并且罩子不能罩住弹出框。
效果如下:
代码如下:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>弹出框练习</title>
<style type="text/css">
.pop{
width:400px;
height:200px;
border:5px solid #000;
background-color:red;
left:50%;
top:50%;
margin-left:-200px;
margin-top:-100px;
z-index:9;
position:fixed;
display:none;
}
.sun{
position:fixed;
background-color:#000;
width:100%;
height:100%;
left:0;
top:0;
opacity:0.3;
z-index:4;
display:none;
}
</style>
<script type="text/javascript">
window.onload=function(){
var pop=document.getElementById("btn")
var sun=document.getElementById("btn1")
var button=document.getElementById("button")
button.onclick=function(){
setTimeout(myalert,4000);
}
function myalert(){
pop.style.display="block";
sun.style.display="block";
}
}
</script>
</head>
<body>
<input type="button" id="button" value="Click">
<div id="btn" class="pop" display="none">弹出框</div>
<div id="btn1" class="sun" display="none"></div>
</body>
</html>