在对话框关闭时添加监听器?

时间:2014-03-26 15:08:00

标签: javascript jquery jquery-ui

在这个小提琴中会显示一个对话框:

http://jsfiddle.net/6M5g4/

小提琴代码:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Dialog - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.9.1.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
  $(function() {
    $( "#dialog" ).dialog();
  });
  </script>
</head>
<body>

<div id="dialog" title="Basic dialog">
  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>


</body>
</html>

是否有一个可以添加的侦听器,如果单击“X”按钮,或者对话框被对话框上的按钮关闭,则会触发?

1 个答案:

答案 0 :(得分:1)

当然,请使用对话框的close event

$(function () {
    $("#dialog").dialog({
        close: function (event, ui) {
            alert('Closed!')
        }
    });
});

<强> jsFiddle example