2017-04-15 43 views
0

代码:如何在3秒后打开一个模态?

<script> 
    $(document).ready(function() 
    { 
     setInterval(function() 
     { 
      $('#contact').modal(); 
     }, 3000); 
    }); 
</script> 

的html代码:

<a href="#contact"><h4><i class="fa fa-phone"></i>Contact Us</h4></a> 
<div id="contact" class="modalDialog"> 
<div> 
    <a href="#close" title="Close" class="close">X</a> 
    <h2>Thanks For Visiting Us</h2> 
    <form method="post"> 
     <input type="text" name="name" id="name" placeholder="Enter Your Name"> 
     <input type="text" name="email" id="email" placeholder="Enter Your Email"> 
     <input type="text" name="phone" id="phone" placeholder="Enter Your Phone"> 
     <input type="text" name="message" id="message" placeholder="Enter Your Message"> 
     <input name="captcha_code" type="text" value="" placeholder="Enter the code"> 
     <img src="captcha.php" id="capImage"/> 
     <br/>Can't read the image? click here to <a href="javascript:void(0);" onclick="javascript:$('#capImage').attr('src','captcha.php');">refresh</a>. 
     <input type="submit" name="insert" id="insert" value="Submit" placeholder="Enter Your Message" > 
    </form> 
</div> 

我想在页面加载是后3秒模式将打开。在这里,我在3秒后使用setinterval方法打开模态,但它不能。那么,如何使用setinterval方法在3秒后打开模态?

谢谢

回答

1

的第一件事是确保你已经包括bootstrap.min.js

变化这个网站

 id="contact" class="modalDialog"

 id="contact" class="modal"

当您使用.modal()函数时,该模型的主类应该是“模态”的。 你的脚本功能工作正常,只需更改类。

0

使用setTimeout函数

$(window).on('load', function($) { 
    setTimeout(function(){ 
    $('#contact').modal(); 
}, 3000); 
    }) 
+0

对不起suresh我在我的问题编辑请再读一遍,然后回答我。我的代码中的 – kevin

+0

在3秒后打开弹出窗口,你需要什么? –