我希望能够检测到被单击的 jQuery UI 对话框的 (x) 关闭按钮,但我不想使用dialogclose
/ dialogbeforeclose
事件(因为我相信无论对话框如何关闭,这些事件都会触发)。
I tried $(".ui-dialog-titlebar-close").live("click")
,但这似乎不起作用。
我怎样才能做到这一点?
示例代码:(对话框关闭时调试器不会启动)。
<!DOCTYPE html>
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.js"></script>
<script>
$(document).ready(function() {
$("#dialog").dialog();
$(".ui-dialog-titlebar-close").live("click", function() {
debugger; // ** clicking the close button doesn't get to here.**
});
});
</script>
</head>
<div id="dialog" title="Dialog Title">I'm in a dialog</div>
</body>
</html>
你完全可以做什么JAAulde建议,或避免跟踪绑定并使用create
event:
$(document).ready(function() {
$('#dialog').dialog({
create: function() {
$(this).closest('div.ui-dialog')
.find('.ui-dialog-titlebar-close')
.click(function(e) {
alert('hi');
e.preventDefault();
});
}
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)