我有这种模式对话,
$("#dialog").dialog({
autoOpen: false,
resizable: false,
width: 400,
height: 140,
modal: true,
buttons: {
"SUBMIT": function() {
$(this).dialog("close");
},
"CANCEL": function() {
$(this).dialog("close");
}
},
close: function() {
alert('close');
}
});
一旦我点击模态对手的x按钮,我就会试图提醒('关闭')。
但问题是,即使在提交了我的模态'#dialog'的bitton和cancel按钮后,也会调用此警报('close')。
有没有什么方法可以让我发出警报,只有点击我的拨号盘的“X”框而不是点击sublit或取消按钮。
然而$(this).dialog(“close”);应该在提交和取消按钮事件中。
如果我删除$(this).dialog(“close”);它的工作。
我想仅在点击'X'时获得提醒,而不是在关闭模式拨号上。
有谁可以帮我解决这个问题?
由于
答案 0 :(得分:0)
close()回调将传递一个事件对象,该对象包含一个.currentTarget属性,表示按下的按钮。您可以使用它来找出单击了哪个按钮。例如,尝试类似
的内容$("#dialog").dialog({
close: function(event,ui) {
if($(event.currentTarget).hasClass('ui-dialog-titlebar-close')
{
alert('close');
}
}
您也可以尝试直接在X按钮上直接创建一个on(“click”)功能,但这可能有点不稳定。