如何让模态对话框在 2 秒后自动打开?
How do I make a Modal Dialog Box Auto Open after 2 seconds?
如何让这个 2 秒后自动打开?
我正在使用 Jquery 模态对话框。我正在使用 jquery、经典 asp 和 Internet Explorer
$(function() {
$("#dialog-message").dialog({
title: "OTHER PARTICIPANTS ALERT",
dialogClass: "alert",
modal: false,
center: true,
autoOpen: false,
width: '600px',
minheight: '600px',
show: 'fade',
autoOption: true,
resizable: false,
buttons: {
Ok: function() {
$(this).dialog("close");
}
}
});
$(" #dialog-message").each(function() {
setTimeout(function() {
$(this).dialog("open");
}, 2000)
});
});
除了一些语法错误外,问题似乎出在 this
.
的范围上
在 setTimeout
范围内,this
不引用该元素。您需要在函数外捕获对 this
的引用:
$("#dialog-message").each(function() {
var self = this;
setTimeout(function() {
$(self).dialog("open");
}, 2000);
});
因为您是通过 id
选择一个元素,所以您实际上可以简单地使用以下代码:
setTimeout(function() {
$("#dialog-message").dialog("open");
}, 2000);
如何让这个 2 秒后自动打开? 我正在使用 Jquery 模态对话框。我正在使用 jquery、经典 asp 和 Internet Explorer
$(function() {
$("#dialog-message").dialog({
title: "OTHER PARTICIPANTS ALERT",
dialogClass: "alert",
modal: false,
center: true,
autoOpen: false,
width: '600px',
minheight: '600px',
show: 'fade',
autoOption: true,
resizable: false,
buttons: {
Ok: function() {
$(this).dialog("close");
}
}
});
$(" #dialog-message").each(function() {
setTimeout(function() {
$(this).dialog("open");
}, 2000)
});
});
除了一些语法错误外,问题似乎出在 this
.
在 setTimeout
范围内,this
不引用该元素。您需要在函数外捕获对 this
的引用:
$("#dialog-message").each(function() {
var self = this;
setTimeout(function() {
$(self).dialog("open");
}, 2000);
});
因为您是通过 id
选择一个元素,所以您实际上可以简单地使用以下代码:
setTimeout(function() {
$("#dialog-message").dialog("open");
}, 2000);