我想用JavaScript显示和隐藏div。 有人有额外的代码吗?到目前为止,这是我的代码:
<script>
window.onload=function(){$hide.div(div)};
</script>
HTML:
<div class="overlay"></div>
<div class="modal">I'm the modal window!</div>
CSS:
.overlay {
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: rgba(0,0,0,0.5);
z-index: 10;
}
.modal {
width: 300px;
height: 200px;
line-height: 200px;
position: fixed;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -150px;
background-color: #f1c40f;
border-radius: 5px;
text-align: center;
z-index: 11;
}
答案 0 :(得分:2)
使用javascript:
<script>
window.onload=function(){
for(var i = 0;i < document.getElementsByTagName("div").length;i++) {
document.getElementsByTagName("div")[i].style.visibility = "hidden";
}
};
</script>
我建议您使用jQuery:
<script>
$(document).ready(function() {
$("div").hide();
});
</script>
答案 1 :(得分:2)