bootstrap 彈出框點擊其他區(qū)域時彈出框不消失選項設(shè)置

bootstrap by 黃業(yè)興 at 2020-04-29

默認情況下,bootstrap 彈出框點擊其他區(qū)域時,彈出框會自動關(guān)閉,在很多時候,我們可能會希望達到和原生彈出框一樣的效果,避免不小心點擊其他區(qū)域時彈框自動隱藏,尤其是對于一些復(fù)雜的表單,重復(fù)填寫可能會帶來很不好的體驗效果,所以,我們會希望不會發(fā)生這種情況。如下所示:

<div class="modal fade" id="myModal" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">模態(tài)框(Modal)標題</h4>
            </div>
            <div class="modal-body">按下 ESC 按鈕退出。</div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">關(guān)閉</button>
                <button type="button" class="btn btn-primary">提交更改</button>
            </div>
        </div>
    </div>
</div>

上面這段代碼就可以實現(xiàn)這個效果,主要是在modal添加這段代碼

data-backdrop="static"

請關(guān)注我們微信公眾號:mw748219