gpt4 book ai didi

javascript - jquery对话框打开和关闭不起作用

转载 作者:行者123 更新时间:2023-12-02 20:37:28 24 4
gpt4 key购买 nike

我想在 n 秒后显示对话框并在 m 秒后隐藏它,但它对我不起作用!

 $(document).ready(function () {
var advanced = $("div#advanced");
$(advanced).dialog({ autoOpen: false,
modal: true,
buttons: { "Try it now": function () { window.location = 'myURL'; },
"No thank's": function () { $(this).dialog("close"); }
},
show: 'fade',
width: 350,
height: 130,
draggable: false,
resizable: false
});
window.setTimeout(function () {
$(advanced).dialog("open");
}, n);
window.setTimeout(function () {
$(advanced).dialog("close");
}, m);});

最佳答案

将触发对话框关闭的 setTimeout 移动到打开对话框的计时器的回调中。您可能还想在对话框关闭时清除计时器。

 $(function () {
var advanced = $("div#advanced");
advanced.dialog({ autoOpen: false,
modal: true,
buttons: { "Try it now": function () {
window.location = 'myURL';
},
"No thank's": function () {
$(this).dialog("close");;
}
},
close: clearTimer,
show: 'fade',
width: 350,
height: 130,
draggable: false,
resizable: false
});
var closeTimer = null;

setTimeout(function () {
advanced.dialog("open");
closeTimer = setTimeout( function() {
closeTimer = null;
advanced.dialog("close");
}, m );
}, n);

function clearTimer() {
if (closeTimer) {
clearTimeout(closeTimer);
closeTimer = null;
}
}

});

关于javascript - jquery对话框打开和关闭不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2980221/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com