首先我们得实现html 样式
<button class="btn">切换</button>
<div id ='box' class="cba" title="aaa" style="color: coral;"> 我u我问问</div>
在js 中获取dom 元素
// 1.获取元素
var btn=document.querySelector('.btn')
var box1=document.querySelector('#box')
监听按钮的点击事件
方案1
if(box1.hidden===true){
box1.hidden=false
}else{
box1.hidden=true
}
方案2:
btn.onclick=function(){
box1.hidden=!box1.hidden
}
方案3:
btn.onclick=function(){
//将原来的属性box盒子切换
box.hidden=true
}
效果如下: