我试图将此灯箱代码转换为能够在加载时打开,而不是点击链接(我想删除)。
我似乎无法让它发挥作用。有什么想法吗?
<a href="javascript:void(0)" onclick="document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">
Show PopUp</a>
<div class="white_content" id="light">
<a class="textright" href="javascript:void(0)" onclick="document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'">
Close</a>
<div id="lbcontent">
<p>THIS IS MY LIGHTBOX CONTENT</p>
</div>
</div>
<div class="black_overlay" id="fade"></div>
答案 0 :(得分:1)
<script>
document.addEventListener('load', function() {
document.getElementById('light').style.display='block';
document.getElementById('fade').style.display='block'
}, false);
</script>
答案 1 :(得分:0)
创建一个js函数loadLightBox并将其命名为onload of body tag
<script language="javascript">
function loadLightBox()
{
document.getElementById('light').style.display='block';
document.getElementById('fade').style.display='block';
}
</script>
<body onload = "loadLightBox()">
...