0

我有一个脚本可以在单击时加载弹出窗口。是否可以在页面加载时自动加载弹出窗口?这是代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
<title>A Simple Lightweight jQuery Modal Popup Box.</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<link href="modalPopLite.css" rel="stylesheet" type="text/css" />
<script src="modalPopLite.min.js" type="text/javascript"></script>

<style type="text/css">
    /* CSS Reset */
    body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td { 
        margin:0;
        padding:0;
        font-family: Verdana, Arial, "Lucida Grande", sans-serif;
    }        

    #clicker
    {
        font-size:20px;
        cursor:pointer;
    }
    #popup-wrapper
    {
        width:500px;
        height:300px;
        background-color:#ccc;
        padding:10px;

    }
    body
    {
        padding:10px;
    }
</style>


<script type="text/javascript">
    $(function () {

        $('#popup-wrapper').modalPopLite({ openButton: '#clicker', closeButton: '#close-btn', isModal: true });

    });
</script>

    </head>
     <body>    
<div id="clicker">
    Click Me!
</div>

<div id="popup-wrapper">
    I am a popup box. Content can be anything. <br />
    <a href="#" id="close-btn">Close</a>
</div>
</body>
</html>

完整代码位于http://www.mywebdeveloperblog.com/my-jquery-plugins/modalpoplite

有什么建议么?:)

4

1 回答 1

-1

该插件似乎没有按需显示弹出窗口的方法。所以你必须模拟点击 clicker 元素:

$(function () {

    $('#popup-wrapper').modalPopLite({ openButton: '#clicker', closeButton: '#close-btn', isModal: true });

    $('#clicker').click(); /* Display popup */

});
于 2012-12-23T08:44:52.143 回答