繁体   English   中英

如何从JQuery UI对话框中的按钮关闭窗口

[英]How to close a window from button in JQuery UI dialog box

我想在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/

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM