引导模式在 4 秒或用户点击后关闭

bootstrap modal close after 4 seconds or user click(引导模式在 4 秒或用户点击后关闭)
本文介绍了引导模式在 4 秒或用户点击后关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

$('#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');
            }
        });
    });
});

推荐答案

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

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

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

这篇关于引导模式在 4 秒或用户点击后关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to trim() white spaces from a string?(如何从字符串中去掉()空格?)
price depend on selection of radio input(价格取决于无线电输入的选择)
calculate price depend on selection without button(根据没有按钮的选择计算价格)
How to minify json response?(如何缩小JSON反应?)
Laravel 5.3 with Vuejs ajax call尝试使用 Vuejs 从数据库中获取一些数据。我的用户表中有一些虚拟数据。我想在我的视野中展示它们。问题是虽然页面加载,但...
Passing Data between react components(在Reaction组件之间传递数据)