twitter-bootstrap 无法通过数据属性数据背景关闭引导模式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26251455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 21:41:16  来源:igfitidea点击:

Can't close bootstrap modal via data-attribute data-backdrop

twitter-bootstrap

提问by lalexa

I want to closemy modal with a click on background. For this I want to usedata-attribute data-backdrop, like this:

我想通过单击 background关闭我的模式。为此,我想使用data-attribute data-backdrop,如下所示:

<div id="myModal" class="modal fade" role="dialog" data-backdrop="">
    <div class="modal-dialog">
        <div class="modal-content">
            <a class="link">
                <img src="URL" />
            </a>
        </div>
    </div>
</div>

Where is a problem?

哪里有问题?

Thanks for your attention.

感谢您的关注。

采纳答案by BENARD Patrick

Because you have to use data-backdrop="true"

因为你必须使用 data-backdrop="true"

See this bootply: http://www.bootply.com/kDYLtTapC4

看到这个引导http: //www.bootply.com/kDYLtTapC4

HTML:

HTML:

<a href="#myModal" role="button" class="btn btn-default" data-toggle="modal">Launch demo modal</a>

<div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="true">   // <----- HERE
<div class="modal-dialog">
<div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="myModalLabel">Modal header</h3>
    </div>
    <div class="modal-body">
        <p>One fine body…</p>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        <button class="btn btn-primary">Save changes</button>
    </div>
</div>
</div>
</div>