在 jQuery 模型对话框关闭上调用函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17986281/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
calling a function on jQuery model dialog close
提问by Robz
I have a small problem related to the jQuery modal dialog box. The scenario is such:
我有一个与 jQuery 模式对话框相关的小问题。场景是这样的:
I have to call a function when i exit or close the dialog box by pressing the cross[x] button on the top right.
当我退出或关闭对话框时,我必须通过按下右上角的十字 [x] 按钮来调用一个函数。
回答by Tushar Gupta - curioustushar
$( ".selector" ).dialog({
close: function( event, ui ) {
//write your function here or call function here
}
});
回答by Dinesh
Solution 1:Initialize the dialog with the close callback specified:
解决方案 1:使用指定的关闭回调初始化对话框:
$( ".selector" ).dialog({
close: function( event, ui ) {**functionCall();**}
});
Solution 2:Bind an event listener to the dialogclose event:
方案二:给dialogclose事件绑定一个事件监听器:
$( ".selector" ).on( "dialogclose", function( event, ui ) { functionCall();} );
回答by faazshift
You have to set the 'close' callback when you create the dialog box. Here is the documentation and an example:
创建对话框时,您必须设置“关闭”回调。这是文档和示例:
回答by Dinesh
//Image tag
<img src="" id="cross">
//jquery
$('#cross').click( function () {
// your function definition goes here
});