如何通过单击jquery UI对话框中的交叉图标来检查用户是否已关闭对话框

时间:2010-12-01 08:55:41

标签: jquery jquery-ui-dialog

我有两个对话框。用户在第一个中选择一些值,它反映在页面的DOM中。第一个对话框关闭,另一个对话框显示。如果用户单击右上角的十字按钮以关闭对话框,我想还原在前一个对话框中所做的更改。在OK按钮上,我必须通过设置值来做一些事情。在这个按钮上,我正在关闭对话框。在关闭事件,到现在为止我有代码重置表单。但是,如果用户取消对话框,我怎么知道,如何触发关闭事件,即从OK按钮或十字按钮?

4 个答案:

答案 0 :(得分:7)

你可以在它的类.ui-dialog-titlebar-close找到“X”按钮,然后在创建对话框时附加一个click处理程序,如下所示:

$("#test").dialog({
    //dialog options...
}).parent().find(".ui-dialog-titlebar-close").click(function() {
    alert("Closed by title bar X, clear the other form here");
});

You can test it here

答案 1 :(得分:3)

您可以使用beforeClose事件

答案 2 :(得分:1)

使用型号ID

$('#myModalId').on('show.bs.modal', function (e) {
  // Do your operation
})

使用模式类

$('.myModalClass').on('show.bs.modal', function (e) {
  // Do your operation
})

<强>模型

<div class="modal fade myModalClass" id="myModalId" role="dialog">
    // your code
</div>

在此处阅读更多内容http://getbootstrap.com/javascript/#modals

答案 3 :(得分:0)

我发现解决方案here对@Vickel很有用

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' )
}
相关问题