在页面加载时显示JavaScript弹出窗口

在页面加载时显示JavaScript弹出窗口,javascript,jquery,html,popup,popupwindow,Javascript,Jquery,Html,Popup,Popupwindow,我有一个简单的弹出窗口(没有任何内容),它将加载“onclick”事件。如何修改以下代码,使弹出窗口在页面加载时以相同的方式显示 <head> <title>Popup box</title> <script type="text/javascript"> <!-- function showPopUpBox(id) { var e = document.g

我有一个简单的弹出窗口(没有任何内容),它将加载“onclick”事件。如何修改以下代码,使弹出窗口在页面加载时以相同的方式显示

<head>
    <title>Popup box</title>
    <script type="text/javascript">
        <!--
            function showPopUpBox(id) {
               var e = document.getElementById(id);
               if(e.style.display == 'block')
                  e.style.display = 'none';
               else
                  e.style.display = 'block';
            }
        //-->
    </script>
</head>

<body>

    <div id="popupBoxPosition">
        <div class="popupBoxWrapper">
            <div class="popupBoxContent">
                <h3>Popup Box</h3>
                <p>Form will be held here</p>
                <p>Click <a href="javascript:void(0)" onclick="showPopUpBox('popupBoxPosition');">here</a> to close popup box</p>
            </div>
        </div>
    </div>
    <div id="wrapper">
        <p>Click <a href="javascript:void(0)" onclick="showPopUpBox('popupBoxPosition');">here</a> to see popup box</p>
    </div><!-- wrapper end -->
</body>

弹出框
弹出框
表格将在这里保存

单击关闭弹出框

单击以查看弹出框


window.onload=函数(){
函数显示弹出框(id){
var e=document.getElementById(id);
如果(e.style.display=='block')
e、 style.display='none';
其他的
e、 style.display='block';
}
showPopuBox();
}

调用
$(document.ready(function(){…}))中的函数
这将阻止联机处理程序调用
showPopuBox
。您可以看到HTML中有几个带有
onclick=“showPopuBox(…)
”属性的链接。您已经将
showPopUpBox
的作用域限定在加载处理程序函数中,现在单击这些链接会导致错误。
<script type="text/javascript">
window.onload = function(){



            function showPopUpBox(id) {
               var e = document.getElementById(id);
               if(e.style.display == 'block')
                  e.style.display = 'none';
               else
                  e.style.display = 'block';
            }

            showPopUpBox();

}

</script>