我在我的网站中使用Jquery UI对话框,想知道是否有办法可以使用关闭按钮执行操作。例如,如果按下按钮,则刷新页面。像这样的东西。这可能吗?
谢谢你们。 :)
$(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>
&#13;
答案 0 :(得分:1)
您可以使用jquery ui对话框的事件dialogbeforeclose
,如下所示:
事件处理的javascript部分:
$("#dialog1").on("dialogbeforeclose", function() {
alert("Do what you want here");
});
如果您愿意,可以通过调用location.reload();
工作片段:
$(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>
答案 1 :(得分:0)
$('#dialog1').on('dialogclose', function(event) {
location.reload();
});