<style>
div{
width: 300px;
height: 300px;
background-color: red;
transition: .4s;
}
</style>
</head>
<body>
<button>显示</button>
<button>隐藏</button>
<div></div>
<script>
var btn = document.getElementsByTagName("button");
var div = document.getElementsByTagName("div")[0]; //不加0是伪数组
//显示
btn[0].onclick = function(){
// div.style.display="block";
div.style.opacity=1;
}
//隐藏
btn[1].onclick = function(){
// div.style.display="none";
div.style.opacity=0;
}
</script>
</body>
2.style样式,一个按钮:显示/隐藏
<style>