admin管理员组文章数量:1356735
I have a jQuery dialog and I need to execute some_code()
when I press Esc or click the Cancel button. The latter is easy to implement, I just add define a property of the buttons
object:
$('#mydialog').dialog({
closeOnEscape: true,
close: function(event, ui) {
//some_code();
$(this).dialog('destroy')
},
buttons: {
"OK": function() {
$(this).dialog("close");
},
"Cancel": function() {
some_code();
$(this).dialog("close");
}
}
});
But how can I execute some_code()
after pressing Esc? This function must not be called clicking the OK button, so I cannot simply place it in the close
event.
I have a jQuery dialog and I need to execute some_code()
when I press Esc or click the Cancel button. The latter is easy to implement, I just add define a property of the buttons
object:
$('#mydialog').dialog({
closeOnEscape: true,
close: function(event, ui) {
//some_code();
$(this).dialog('destroy')
},
buttons: {
"OK": function() {
$(this).dialog("close");
},
"Cancel": function() {
some_code();
$(this).dialog("close");
}
}
});
But how can I execute some_code()
after pressing Esc? This function must not be called clicking the OK button, so I cannot simply place it in the close
event.
1 Answer
Reset to default 13 +500After googling around without finding an answer, I started looking into close: function(event, ui)
part and found the solution using event.originalEvent
(JSFiddle):
close: function(event, ui) {
// some_code();
if (event.originalEvent) {
// triggered by clicking on dialog box X or pressing ESC
// not triggered if a dialog button was clicked
some_code();
}
$(this).dialog('destroy')
}
本文标签: javascriptHow can I execute some code if jQuery dialog was closed on escapeStack Overflow
版权声明:本文标题:javascript - How can I execute some code if jQuery dialog was closed on escape? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743969660a2570525.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论