首先我们定义好html结构,noe为遮罩层的结构
<body>
<input type="button" value="按钮">
<div id="noe">
<div id="tow">
</div>
</div>
</body>
使用css样式,首先使noe遮罩层隐藏
<style>
#noe {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
display: none;
background-color: rgba(0, 0, 0, 0.6);
}
#noe #tow {
width: 500px;
height: 350px;
background-color: #fff;
margin: 150px auto;
}
</style>
下面是js代码
<script>
var input = document.getElementsByTagName("input")[0];
var noe = document.getElementById("noe");
input.onclick = function () {
noe.style.display = "block";
}
noe.onclick = function () {
noe.style.display = "none";
}
</script>
全部代码 下面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
#noe {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
display: none;
background-color: rgba(0, 0, 0, 0.6);
}
#noe #tow {
width: 500px;
height: 350px;
background-color: #fff;
margin: 150px auto;
}
</style>
</head>
<body>
<input type="button" value="按钮">
<div id="noe">
<div id="tow">
</div>
</div>
</body>
<script>
var input = document.getElementsByTagName("input")[0];
var noe = document.getElementById("noe");
input.onclick = function () {
noe.style.display = "block";
}
noe.onclick = function () {
noe.style.display = "none";
}
</script>
</html>