2013-11-03 34 views
2

我的主頁上有一個歡迎的彈出窗口。在javascript中設置延遲時間

我有此Javascript

<script type="text/javascript"> 
    $(document).ready(function() { 
     $("#div-welcome").dialog({ 
       width: 'auto', 
       height: 'auto', 
       modal: true 
     }); 
    }); 
</script> 

如何設置3秒的延遲?我嘗試了setTime函數,但沒有奏效。也許我把它放在了錯誤的地方。 謝謝! AVersa

+0

類似的問題,http://stackoverflow.com/questions/17305879/load-jquery-modal-dialog-after-a-delay –

回答

0
$(document).ready(function() { 
    window.setTimeout(function() { 
     $("#div-welcome").dialog({ 
       width: 'auto', 
       height: 'auto', 
       modal: true 
     }); 
    }, 3000); 
}); 
+0

非常感謝!祝你今天愉快! – AVersa

+0

Np!順便說一句,如果你滿意,請接受答案。 –

1

使用setTimeout

setTimeout()方法在指定的毫秒數後調用函數或評估表達式。

這樣寫:

$(document).ready(function() { 
    setTimeout(function(){ 
     $("#div-welcome").dialog({ 
      width: 'auto', 
      height: 'auto', 
      modal: true 
     }); 
    },3000); 
});