簡體   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