Javascript 引导模式事件-等待回调完成,然后返回

Javascript 引导模式事件-等待回调完成,然后返回,javascript,jquery,twitter-bootstrap,bootstrap-modal,Javascript,Jquery,Twitter Bootstrap,Bootstrap Modal,我知道这个问题听起来很幼稚,但想不出其他的标题 我正在使用一个bootstrapmodel事件hide.bs.modal,它在模式消失之前被调用,以显示一个确认框。回调需要一个布尔值 $('#the-modal').on('hide.bs.modal', function () { var self = this; $.cofirm("are your sure you want to close", function() { // gets fired if confirmed

我知道这个问题听起来很幼稚,但想不出其他的标题

我正在使用一个
bootstrapmodel
事件
hide.bs.modal
,它在模式消失之前被调用,以显示一个确认框。回调需要一个布尔值

$('#the-modal').on('hide.bs.modal', function () {
   var self = this;

   $.cofirm("are your sure you want to close", function() { // gets fired if confirmed
       $(self).modal("hide"); // cannot do this,it will fire the event hide.bs.modal over and over.
   });

   return false; // obviously, this gets called first, but that's alright
}
另外,我使用了一个jquery插件,它有自己的回调,而不是使用传统的
确认


$(self.modal(“隐藏”)
无法做到这一点,它将反复触发事件
hide.bs.modal

您需要一个标志来知道访问者是否确认了它。您可以这样做(使用元素的数据):

$('#myModal').on('hide.bs.modal',function(){
var thisModal=$(本);
var ThisConfirm=thisModal.data(“已确认”);
如果(!已确认){
美元。确认({
标题:“你确定吗?”,
内容:“”,
按钮:{
确认:函数(){
thisModal.data(‘已确认’、真实);
thisModal.modal('hide');
},
取消:函数(){
/*这里什么都没有*/
}
}
});
返回false;
}否则{
thisModal.data(‘已确认’、假);
返回true;
};
});

开放模态
新消息
&时代;
收件人:
信息:
接近
发送消息

您签出了这张支票吗?它使用
event.preventDefault()
停止模式关闭。