data-target =“#my-modal”应该放在Twitter Bootstrap中的模态div中吗?

时间:2015-06-03 15:39:16

标签: twitter-bootstrap modal-dialog bootstrap-modal dismiss

我知道将data-target="#my-modal"放在模态div之外的启动按钮是必要的。但是我是否应该将该代码放在modal div中的dismiss按钮中?或者机器总是知道要将模态div放在哪里?

<button class="btn btn-success" data-toggle="modal" data-target="#my-modal">Launch Modal</button>

    <div class="modal" id="my-modal"> <!-- this is modal div -->
        <div class="modal-dialog modal-md">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal">x</button> <!-- put `data-target="#my-modal"` in? -->
                    <h4 class="modal-title">Hello User!</h4>
                </div>
                <div class="modal-body">
                    Welcome our dear user of our website!
                </div>
                <div class="modal-footer">
                    <button class="btn btn-default" data-dismiss="modal">Dismiss</button> <!-- put `data-target="#my-modal"` in? -->
                    <button class="btn btn-success">Save Changes</button>
                </div>
            </div>
        </div>

Additonal Info:这就是它的样子。 enter image description here

1 个答案:

答案 0 :(得分:1)

只需拥有如下data-dismiss="modal"即可:

<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>

然而,使用多个模态 NOT 支持引用here。如果您希望一次打开多个模态,则需要编写自定义javascript。