如何使用延迟计时器在页面加载时使我的模态窗体弹出窗口

时间:2015-03-09 10:51:35

标签: jquery modal-dialog popupmenu

我正在建立一个网站,需要一个表格,当用户登陆页面时会弹出一个延迟计时器...

我无法弹出表格。我做错了什么?

定时器

setTimeout(popup, 10000); // Setting time 3s to popup login form
function popup() {
    $("#openModal").css("display", "block");
}

弹出窗体

<div id="openModal">
    <a href="#x" class="overlay" ></a>
    <div class="popup">
        <h2>Just Stopping By</h2>
        <p>Please enter your details here</p>
        <div>
            <label for="firstname">First Name:</label>
            <input type="text" id="firstname" value="" placeholder="First Name*" />
        </div>
        <div>
            <label for="lastname">Last Name:</label>
            <input type="text" id="lastname" value="" placeholder="Last Name*" />
        </div>
        <div>
            <label for="email">Email:</label>
            <input type="text" id="email" value="" placeholder="Email Address*" />
        </div>
        <div>
            <label for="phone">Phone:</label>
            <input type="text" id="phone" value="" placeholder="Phone Number*" />
        </div>
        <center><input class="button-primary" type="button" value="Submit!" /></center>
        <a class="close" href="#close"></a>
    </div>
</div>

1 个答案:

答案 0 :(得分:1)

当dom准备就绪时,你应该使用setTimeout:

$(function(){//document ready event
   setTimeout(function(){
        $("#openModal").show();
   },3000);//set interval to 3 second
});