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()
函数,所以我不得不对它进行一些修改:)