<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta content="IE=edge" http-equiv="X-UA-Compatible"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<title>div盒子消失</title>
</head>
<style>
#box1 {
width: 400px;
height: 400px;
background-color: pink;
display: block;
}
#box2 {
width: 200px;
height: 200px;
background-color: blue;
}
</style>
<script type="text/javascript">
var div = document.getElementById("box1");
var a=true;
function toggle(){
a=!a;
a?box1.style.display='block':box1.style.display='none';
}
</script>
<body>
<div id="box1">
我是盒子box1
<div id="box2">
我是盒子box2
</div>
</div>
<button onclick="toggle();">
点我消失盒子
</button>
</body>
</html>