是否有办法限制在重新加载页面之前触发对话框的次数?具体来说,我正在使用jQuery UI Dialog Widget。我希望有一些方法可以将其提供给小部件的选项 - 我想它看起来像
// div#notice is the name of the dialog element,
// with style="display:none" by default
$("#notice").dialog({
dialogClass: "noticeDialog",
buttons: [{
text: "OK",
click: function() {
$(this).dialog("close");
}
}],
repeat: 1 // A Dialog option equivalent to this does not exist to
// my knowledge
}
我能想到实现这一目标的唯一方法是将对话框中的.remove()本身从“关闭”中的DOM中删除。选项回调函数。类似的东西:
$(".selector").dialog({
close: function() {
$(#"dialogBox").remove();
}
});
但是,我觉得这不会像希望的那样有效。还有哪些更好的选择?如果有一种方法可以在对话框上设置超时,那么这也会有所帮助和/或完成类似的效果。
答案 0 :(得分:0)
在触发对话框的代码中执行此操作。首先,初始化一个计数器:
var dialog_counter = 0;
var dialog_limit = 5;
然后在显示对话框的代码中,递增并测试它:
if (++dialog_counter <= dialog_limit) {
$("#notice").dialog({
...
});
}