【发布时间】:2019-11-07 07:37:21
【问题描述】:
我知道这个问题听起来很幼稚,但想不出其他任何标题。
我正在使用 bootstrap modal 事件之一 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
}
另外,我没有使用传统的 confirm,而是使用了一个 jquery 插件,它有自己的回调。
$(self).modal("hide"); 不能这样做,它会一遍又一遍地触发事件 hide.bs.modal。
【问题讨论】:
-
您查看过这个答案吗? stackoverflow.com/questions/22221637/… 它使用
event.preventDefault()来阻止模态关闭。
标签: javascript jquery twitter-bootstrap bootstrap-modal