#div1{
height: 200px;
width: 500px;
background: skyblue;
display: none;
}
<input type="button" name="" id="button" value="点我点我" />
<div id="div1">
</div>
<script type="text/javascript">
var contant = document.getElementById(‘div1‘);
var Button = document.getElementById(‘button‘);
// var off = true;
//获取操作的标签
Button.onclick = function(){
if(contant.style.display == ‘none‘){
contant.style.display = ‘block‘;//点击需要两次是因为刚开始没有获取到样式。写为div内部样式即可。如:<div id="div1" style="display:none;"> </div>
// off = false;
}
else{
contant.style.display = ‘none‘;
// off = true;
}
}
</script>
时间: 2024-10-12 11:58:14