我正在用bootstrap做一个网站。

基本上,我想在主页中使用一个模态,通过Hero Unit中的按钮来调用。

按钮代码:

<button type="button" 
    class="btn btn-warning btn-large" 
    data-toggle="modal"
    data-target="#myModal">Open Modal</button>

模态代码:

<div class="modal hide fade" id="myModal" 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">In Costruzione</h3>
  </div>
  <div class="modal-body">
    <p>Test Modal: Bootstrap</p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Chiudi</button>
    <button class="btn btn-warning">Salva</button>
  </div>
</div>

问题是,只要我点击按钮,模态就会淡入,然后立即消失。

我很感激你的帮助。

此外,如何改变下拉三角形的颜色(指向向上,没有悬停)?我正在做一个基于橙色和棕色的网站,那个蓝色的东西真的很烦人。


当前回答

如果使用jquery两次附加事件监听器,也会出现这个问题。 例如,你可以在不解除绑定的情况下设置:

            $("body").on("click","#fixerror",function(event){
                $("#fixerrormodal").modal('toggle')
            })

如果发生这种情况,事件将连续触发两次,模态将消失。

            $("body").on("click","#fixerror",function(event){
                $("#fixerrormodal").modal()
                $("#fixerrormodal").modal('toggle')
            })

参见示例:http://embed.plnkr.co/i5xB1WbX7zgXrbDMhNAW/preview

其他回答

我知道这是旧的,但这里还有另一件事要检查—确保您只有一个data-target=属性。我复制了它,结果是按照这个线程。

我在我的mvc应用程序中寻找了一个重复的引导参考,在这个问题上的其他有用的答案之后。

终于找到了——它包含在我正在使用的另一个库中,所以一点也不明显!(datatables.net)。

如果您仍然遇到这个问题,请寻找其他可能为您包含引导的库。(datatables.net允许您指定有或没有引导的下载-其他人也这样做)。

所以我从我的包中删除了bootstrap.min.js。配置和所有工作都很好。

同样的症状,在一个带有Bootstrap -sass gem提供的Bootstrap的Rails应用程序的上下文中,@merv的回答使我走上了正确的轨道。

我的application.js文件有以下内容:

//= require bootstrap
//= require bootstrap-sprockets

解决办法是去掉两条线中的一条。事实上,宝石的自述会警告你这个错误。我的坏。

e.preventDefault ();jquery UI

对我来说,这个问题发生在jquery ui按钮上的click方法覆盖,导致默认情况下单击页面重新加载。

今天我自己也遇到了这个问题,而且碰巧只是在Chrome上。是什么让我意识到这可能是一个渲染问题。 移动特定的模式到它自己的渲染层解决了这个问题。

#myModal {
  -webkit-transform: translate3d(0, 0, 0);
}