Javascript 单击“保存”按钮后删除弹出窗口
HTMLJavascript 单击“保存”按钮后删除弹出窗口,javascript,jquery,twitter-bootstrap,bootbox,Javascript,Jquery,Twitter Bootstrap,Bootbox,HTML <a href="#modal-2" role="button" class="btn" data-toggle="modal">Modal with animation</a> <div id="modal-2" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <
<a href="#modal-2" role="button" class="btn" data-toggle="modal">Modal with animation</a>
<div id="modal-2" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary" id="book" >Save changes</button>
</div>
</div>
在这里,我想在单击save按钮后在callback中调用一个ajax函数。
在ajax成功后,我想关闭bootbox弹出窗口如果要使用bootbox,可以执行以下操作:
bootbox.dialog({
message: "Your Message Here - You can pass in an HTML string",
title: "Your Title",
onEscape: function () {
bootbox.hideAll();
},
buttons: {
danger: {
label: "Cancel",
className: "btn default",
callback: function () {
bootbox.hideAll();
}
},
success: {
label: "Add",
className: "btn blue",
callback: function () {
//Add functionality here
// Then close the model using
bootbox.hideAll();
}
}
}
});
在ajax定义中,您应该使用参数
async : false
您可能需要在模式窗口主体内使用自定义按钮,而不是从引导框中使用这些按钮我无法关闭弹出窗口在JSFIDLE中运行代码时关闭弹出窗口没有问题。您有一个问题,您将“hide”添加到modal的类中,这将阻止modal打开。可能还有其他原因导致了问题。你能发布那把小提琴吗?在这里,你可以用ajax成功地获得这美元(“#modal-2”)。modal('hide');不工作不工作,它仍然没有等到ajax完成。它总是在单击按钮后关闭窗口。
async : false