Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 秒后自动关闭弹出窗口_Javascript_Jquery - Fatal编程技术网

Javascript 秒后自动关闭弹出窗口

Javascript 秒后自动关闭弹出窗口,javascript,jquery,Javascript,Jquery,我使用简单的弹出窗口,我想在几秒钟后自动关闭弹出窗口。请指导我怎么做 jQuery(document).ready(function($) { $(".movenext").on("click", function(e) { e.preventDefault(); $(this).simplePopup({ type: "html", htmlSelector: "#popupuser"},

我使用简单的弹出窗口,我想在几秒钟后自动关闭弹出窗口。请指导我怎么做

jQuery(document).ready(function($) {
    $(".movenext").on("click", function(e) {
        e.preventDefault();
        $(this).simplePopup({
            type: "html",
            htmlSelector: "#popupuser"},
            setTimeout(function(){
                $(this).simplePopup().close();
            }, 3000)
        );                                      
    });
});

给予setTimeout的回调没有“this”值。使用变量存储$(this),并在setTimeout回调中使用它

jQuery(document).ready(function($) {
    $(".movenext").on("click", function(e) {
        e.preventDefault();
        var element = $(this);
        element.simplePopup({
            type: "html",
            htmlSelector: "#popupuser"
        });
        setTimeout(function(){
            element.simplePopup().close();
        }, 3000);
    });
});

给予setTimeout的回调没有“this”值。使用变量存储$(this),并在setTimeout回调中使用它

jQuery(document).ready(function($) {
    $(".movenext").on("click", function(e) {
        e.preventDefault();
        var element = $(this);
        element.simplePopup({
            type: "html",
            htmlSelector: "#popupuser"
        });
        setTimeout(function(){
            element.simplePopup().close();
        }, 3000);
    });
});
尝试此操作,您将在
setTimeout
回调中失去
this
作用域,看看是否有效

jQuery(document).ready(function($) {
    $(".movenext").on("click", function(e) {
        e.preventDefault();
        var self = this;
        $(this).simplePopup({
                type: "html",
                htmlSelector: "#popupuser"
        });
        setTimeout(function() {
            $('.simple-popup-content .close').click();
        }, 3000);
    });
});
编辑:

我已经更新了你的小提琴,请看这里:

尝试此操作,您将在
setTimeout
回调中失去
this
作用域,看看是否有效

jQuery(document).ready(function($) {
    $(".movenext").on("click", function(e) {
        e.preventDefault();
        var self = this;
        $(this).simplePopup({
                type: "html",
                htmlSelector: "#popupuser"
        });
        setTimeout(function() {
            $('.simple-popup-content .close').click();
        }, 3000);
    });
});
编辑:


我已经更新了你的小提琴,请看这里:

你可以通过
this
作为参数:
setTimeout(函数(self){$(self).simplePopup().close();},3000,this)
Hi@Werner,谢谢你的回复,我正在使用插件,我试图在3秒后自动关闭弹出窗口,但我无法做到这一点,这是我的,请有一个look@Yajuvendrapratapsingh似乎,
simplePopup.js
没有内置的close函数。至少我找不到关于这个的文档。。。然而。这里有一个解决方案:非常感谢@Werner,您可以将
作为参数传递:
setTimeout(函数(self){$(self).simplePopup().close();},3000,this)
Hi@Werner,谢谢你的回复,我正在使用插件,我试图在3秒后自动关闭弹出窗口,但我无法做到这一点,这是我的,请有一个look@Yajuvendrapratapsingh似乎,
simplePopup.js
没有内置的close函数。至少我找不到关于这个的文档。。。然而。这里有一个解决方案:非常感谢你@Wernerhey,@yajuvendrapratapsing我已经更新了你的小提琴和答案。它现在可以工作了,但我不认为自定义jQuery库内置了
close()
函数,所以我不得不对它进行一些修改:)嘿,@yajuvendrapratapsing我已经更新了你的小提琴和答案。它现在可以工作了,但我不认为自定义jQuery库内置了
close()
函数,所以我不得不对它进行一些修改:)