bootstrap模态在4秒后关闭或用户单击

时间:2022-03-22 03:56:00

How would I set a timeout for a bootstrap modal? After getting the ajax data back that the message returned by php contains the term success, I want to give the user the option to close the window. However, I also just want to have a 4 second count down. Currently the second the success message comes back the modal hides itself.

如何为引导模式设置超时?获取ajax数据后,php返回的消息包含术语成功,我想给用户关闭窗口的选项。但是,我也想减少4秒钟。目前第二个成功消息回来,模态隐藏自己。

$('#forgotform').submit(function (e) {
    "use strict";
    e.preventDefault();
    $('#forgotsubmit').button('loading');
    var post = $('#forgotform').serialize();
    var action = $('#forgotform').attr('action');
    $("#message").slideUp(350, function () {
        $('#message').hide();
        $.post(action, post, function (data) {
            $('#message').html(data);
            document.getElementById('message').innerHTML = data;
            $('#message').slideDown('slow');
            $('#usernamemail').focus();
            if (data.match('success') !== null) {
                $('#forgotform').slideUp('slow');
                $('#forgotsubmit').button('complete');
                $('#forgotsubmit').click(function (eb) {
                    eb.preventDefault();
                    $('#forgot-form').modal('hide');
                });
                setTimeout($('#forgot-form').modal('hide'), 10000);
            } else {
                $('#forgotsubmit').button('reset');
            }
        });
    });
});

3 个解决方案

#1


25  

When calling setTimeout(), wrap your command in an anonymous function. Otherwise the command will be executed immediately.

调用setTimeout()时,将命令包装在匿名函数中。否则命令将立即执行。

setTimeout(function() {$('#forgot-form').modal('hide');}, 4000);

#2


13  

setTimeout(function(){
  $('#Modal').modal('hide')
}, 4000);

//where modal's id is 'Modal'

//其中modal的id是'Modal'

#3


0  

$('#submit1').click(function(){
        setTimeout("$('#myModal').modal('hide');",3000);
    });

this is working for popup delaying 3 seconds in closing. please check with the $('#submit1') for this click I have written the code.

这是为了让popup在关闭时延迟3秒。请点击$('#submit1')查看我编写的代码。

#1


25  

When calling setTimeout(), wrap your command in an anonymous function. Otherwise the command will be executed immediately.

调用setTimeout()时,将命令包装在匿名函数中。否则命令将立即执行。

setTimeout(function() {$('#forgot-form').modal('hide');}, 4000);

#2


13  

setTimeout(function(){
  $('#Modal').modal('hide')
}, 4000);

//where modal's id is 'Modal'

//其中modal的id是'Modal'

#3


0  

$('#submit1').click(function(){
        setTimeout("$('#myModal').modal('hide');",3000);
    });

this is working for popup delaying 3 seconds in closing. please check with the $('#submit1') for this click I have written the code.

这是为了让popup在关闭时延迟3秒。请点击$('#submit1')查看我编写的代码。