js_补--模拟对话框

<!DOCTYPE html>
<html lang="en">
<head>
<title>Title</title>
<meta charset="UTF-8">
<!--&lt;!&ndash; <script src="js_file01.js"></script>&ndash;&gt; 尽量放后body前边-->

<style>

*{
margin: 0;
}

#div1{

position: fixed;
z-index: 1000;
top: 0;
left: 0;
width: 100%;
height: 800px;
background-color: #959da5;
}

#div2{
position: fixed;
z-index: 1001;
width: 100%;
/*height: 300px;*/
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: chartreuse;
opacity: 0.3;
}

#div3{
width: 300px;
height: 300px;
position: absolute;
z-index: 1002;
top: 50%;
left: 50%;
margin-top: -150px;
margin-left: -150px;
background-color: red;
}
/*隐藏*/
.hide{
display: none;
}

</style>

</head>
<body>

<div id="div1">
<input type="button" value="click" onclick="show()">
</div>

<div id="div2" class="div hide"></div>

<div id="div3" class="div hide">
<input type="button" value="cancel" onclick="cancel()">
</div>

<script>

function show() {
var el=document.getElementsByClassName("div");
for (var i=0;i<el.length;i++){
el[i].classList.remove("hide");
}
}

function cancel() {
var el=document.getElementsByClassName("div");
for (var i=0;i<el.length;i++){
el[i].classList.add("hide");
}
}

</script>

</body>
</html>
posted @ 2020-08-18 22:25  zxy_ang  阅读(140)  评论(0)    收藏  举报