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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:41:36  来源:igfitidea点击:

Close Modal Box after 10 seconds

jquery

提问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 setTimeoutfunction to delay an action by a number of milliseconds:

使用该setTimeout函数将操作延迟若干毫秒:

setTimeout(function(){
    $('#dialogModal').modal('hide')
}, 10000);

where dialogModalis the dialog's id attribute, and 10000is 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 :)

在尝试关闭模态的所有其他方式后,此代码对我有用:)