背景I有一个引导模式,弹出并显示输入表单,如果用户进行更改并取消/关闭该模式,确认框将识别它们将丢失更改。
模态触发两个事件,当模态开始关闭时触发hide,当模态完全关闭时触发hidden。
我用以下方法拦截hide事件:
.on('hide',function(){
if(confirm('close'))
return true;
else
return false;
});如果我关闭盒子并点击Ok,模态就会关闭。
如果我点击取消模式将保持打开(这是正确的),但我将点击Ok后,它将不会继续默认事件。
我也尝试过preventDefault();,但我不知道如何使事件在取消操作后继续进行。
可以在这里测试:
http://jschr.github.io/bootstrap-modal/
输入控制台:
$('#responsive').on('hide', function() { if(confirm('close)) return true; else return false;});
发布于 2014-01-08 20:21:09
在隐藏函数的引导-modal.js第84行中深入研究模态管理器的源代码:
e && e.preventDefault();
e = $.Event('hide');
this.$element.trigger(e);
if (!this.isShown || e.isDefaultPrevented()) return (this.isShown = false); <--
this.isShown = false;
this.escape();
this.tab();this.isShown设置为false,导致了一个常量循环,应该将其设置为true,因为在触发e.preventDefault()时,该模式并不隐藏。所以解决办法是:
if (!this.isShown || e.isDefaultPrevented()) return (this.isShown = true);发布于 2014-01-08 15:22:15
你用的是什么版本的靴带?
您是否将.on(“隐藏”)事件附加到模态元素?例如:
$('.modal').on('hide', function(){...});我在JS (http://jsfiddle.net/5kbXZ/)中测试了您的代码,使用的是Bootstrap 3模式的示例标记,它在Chrome中为我工作。
https://stackoverflow.com/questions/20999425
复制相似问题