1

我想在 JQuery UI 对话框中单击一个按钮来关闭当前窗口。

我试过window.close()

$(document).ready(function() {
  $("#sessionReason").dialog({
    autoOpen: false,
    modal: true,
    buttons: {
      "Submit": function() {
        window.close();
      },
      "Cancel": function() {
        $(this).dialog("close");
      }
    }
  });
  $("#cancelSessionButton").click(function() {
    $("#sessionReason").dialog("open");
  });
});
<!DOCTYPE html>
<html>
<head>
  <title>jQuery UI Example</title>
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <link href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" rel="stylesheet" />
</head>
<body>
  <input id="cancelSessionButton" type="button" value="Cancel Session" class="redButton" />

  <div id="sessionReason" title="Reason">
    <p>Please provide the reason for cancelling the session.</p>
    <div class="inputRow">
      <textarea id="sessionReasonBox" class="reasonBox"></textarea>
    </div>
  </div>
</body>
</html>

http://jsfiddle.net/d3bxM/

4

1 回答 1

1

您的脚本是否打开了窗口?Firefox 2 和更高版本不允许脚本关闭它们没有打开的窗口。window.close();

仅允许为使用 window.open 方法的脚本打开的窗口调用此方法。

于 2013-11-06T20:59:09.840 回答