jQuery 10 秒后关闭模态框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5180276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Close Modal Box after 10 seconds
提问by Shaun
How can i close the jquery modal box after 10 seconds ???
如何在 10 秒后关闭 jquery 模式框???
回答by gor
Use setTimeOutfunction.
使用setTimeOut函数。
//make sure you have lower case "o"
setTimeout(function(){
$(dialog).close();
}, 10000);
回答by Alex
setTimeout(function() { // code to close the modal }, 10000);
回答by Developer
The jQuery UI modal dialog will automatically open on page load if you declare no other parameters in its initialisation call:
如果在初始化调用中没有声明其他参数,jQuery UI 模态对话框将在页面加载时自动打开:
$(function() {
$( "#dialog" ).dialog();
});
To have the dialog close after a delay you should be able to include a call further down your DOM ready event:
要在延迟后关闭对话框,您应该能够在 DOM 就绪事件中进一步包含调用:
setTimeout($('#dialog').dialog('close'), 10000);
回答by ebentil
Use the setTimeout
function to delay an action by a number of milliseconds:
使用该setTimeout
函数将操作延迟若干毫秒:
setTimeout(function(){
$('#dialogModal').modal('hide')
}, 10000);
where dialogModal
is the dialog's id attribute, and 10000
is a ten second delay in milliseconds.
其中dialogModal
是对话框的 id 属性,10000
是以毫秒为单位的十秒延迟。
You can execute any code in the function block.
您可以执行功能块中的任何代码。
回答by btc4cash
Showing #ads modals on page load then close after 10 seconds :
在页面加载时显示 #ads 模式,然后在 10 秒后关闭:
<script>
$(window).load(function()
{
$('#ads').modal('show');});
$(window).load(function()
{
setTimeout(function(){
$('#ads').modal('hide')
}, 10000);});
</script>
This code working for me after trying all the other way closing modals :)
在尝试关闭模态的所有其他方式后,此代码对我有用:)