在页面加载时显示JavaScript PopUp

时间:2016-03-07 18:38:52

标签: javascript jquery html popup popupwindow

我有一个简单的弹出窗口(里面没有任何内容)会加载'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>

1 个答案:

答案 0 :(得分:0)

<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>
相关问题