简体   繁体   English

jQuery UI对话框-如何使用关闭按钮执行功能?

[英]Jquery UI Dialog - How to use the close button to perform function?

I'm using the Jquery UI Dialog in my site and wanted to know if there is a way that I can use the close button to perform an action. 我在我的网站上使用Jquery UI对话框,想知道是否有一种方法可以使用关闭按钮执行操作。 For example if the button is pressed then refresh the page. 例如,如果按下按钮,则刷新页面。 Something like this. 这样的事情。 Is this possible? 这可能吗?

Thanks guys. 多谢你们。 :) :)

 $(document).ready(function() { $("#dialog1").dialog({ autoOpen: false, show: { effect: "puff", duration: 300 }, hide: { effect: "clip", duration: 500 } }); $("#opener").on("click", function() { $("#dialog1").dialog("open"); }); }); function dialog() { $("#dialog1").dialog("open"); } 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <div id="dialog1" title="Dialog Title!"> <p>Dialog Text</p> </div> <button onclick="dialog()">Press For Dialog</button> 

You can use the event dialogbeforeclose of jquery ui dialog like this: 您可以像这样在jquery ui对话框的dialogbeforeclose之前使用事件dialog:

javascript part of the event handling: 事件处理的javascript部分:

$("#dialog1").on("dialogbeforeclose", function() {
    alert("Do what you want here");
});

You can, if you want, instead of the alert, refresh the page with calling location.reload(); 如果需要,可以代替调用警报来刷新页面,方法是调用location.reload();

Working snippet: 工作片段:

 $(document).ready(function() { $("#dialog1").dialog({ autoOpen: false, show: { effect: "puff", duration: 300 }, hide: { effect: "clip", duration: 500 } }); $("#opener").on("click", function() { $("#dialog1").dialog("open"); }); }); // Here is the interception of the event dialogbeforeclose $("#dialog1").on("dialogbeforeclose", function() { alert("Do what you want here"); }); function dialog() { $("#dialog1").dialog("open"); } 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <div id="dialog1" title="Dialog Title!"> <p>Dialog Text</p> </div> <button onclick="dialog()">Press For Dialog</button> 

$('#dialog1').on('dialogclose', function(event) {
     location.reload();
 });

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

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