[英]javascript bootstrap modal - cancel closing
my work is using javascript bootstrap 2.0.4 我的工作是使用javascript bootstrap 2.0.4
I'm looking for a way to cancel the modal from closing, by logic control. 我正在寻找一种通过逻辑控制取消关闭模式的方法。 but I can't find any details how to do this
但我找不到任何细节如何做到这一点
http://getbootstrap.com/javascript/#modals http://getbootstrap.com/javascript/#modals
something like .NET 像.NET这样的东西
OnWindowClosing(eventArguement)
{
if (shouldCancel) {
eventArguement.Cancel = true;
return;
}
}
Look at here : www.bootply.com/QTTDf3zRgV 请看这里: www.bootply.com/QTTDf3zRgV
In this exemple, if the checkbox is checked, then the modal can't be closed ( with js/jquery): 在这个例子中,如果选中复选框,则无法关闭模态(使用js / jquery):
$('#myModal').on('hide.bs.modal', function(e){
if( $('#block').is(':checked') ) {
e.preventDefault();
e.stopImmediatePropagation();
return false;
}
});
e.cancel
is not defined and causes an error - that's why the solution above is working. e.cancel
未定义并导致错误 - 这就是上述解决方案正常工作的原因。
You should add e.stopImmediatePropagation();
你应该添加
e.stopImmediatePropagation();
Here's a demo: http://www.bootply.com/o5jsyItQMm 这是一个演示: http : //www.bootply.com/o5jsyItQMm
the solution you provided was not working so find this and its the perfect solution referrence here https://github.com/twbs/bootstrap/issues/1202#issuecomment-48601320 你提供的解决方案没有工作所以找到这个及其完美的解决方案参考https://github.com/twbs/bootstrap/issues/1202#issuecomment-48601320
$('#myModal').on('hide.bs.modal.prevent', closeModalEvent);
/**
* allow popup to hide or not
* @param {type} e
* @returns {Boolean}
*/
function closeModalEvent(e) {
e.preventDefault();
if ($('#block').is(':checked')) {
$('#myModal').off('hide.bs.modal.prevent');
$("#myModal").modal('hide');
return true;
}
return false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.