效果:
<html>
<head>
<style type = "text/css">
#div1{
display:block;
background-color:blue;
width:200px;
height:200px;
}
</style>
<script type = "text/javascript">
function toggle() {
var div = document.getElementById("div1");
if (div.style.display == "block" ) {
div.style.display = "none";
} else {
div.style.display = "block";
}
}
</script>
</head>
<body>
<div id = "div1"></div>
<button onclick = "toggle();"> good </button>
</body>
</html>