【问题标题】:bootstrap modal closes when ok on alert() is clicked当点击 ok on alert() 时,引导模式关闭
【发布时间】:2017-11-17 20:53:22
【问题描述】:

当我单击“alert()”函数显示的“确定”按钮时,引导模式正在关闭。

$("#expample").modal({
    backdrop: 'static',
    keyboard: false,
    show: true
});

下面是我的jquery:

$('.sendToUser').on('click', function (){
            var selectedLyrics = $('#selectedLyricsInput').val();
            if($("input[name='selectUserRadio']").is(":checked") == false){
                alert('Please, select a user to send.');
                return;
            }
        });

虽然,在键盘上按“Enter”或“Esc”可以正常工作,并且在模态之外单击;模态没有关闭,这很好。

下面是我的html:

<div class="modal fade" id="userSelectionModal" tabindex="-1" role="dialog" aria-labelledby="userSelectionModal">
    <div class="modal-dialog modal-likes" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Select User</h4>
            </div>

            <div class="modal-body">
                <div style="margin-bottom: 50px;" id="populateUsers">

                </div>
                <input type="hidden" id="selectedLyricsInput" value="" />
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-success sendToUser" data-dismiss="modal">Send</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
            {{--<i class="fa fa-spinner fa-spin"></i>--}}
        </div>
    </div>
</div>

我正在从模式上的事件中创建一个警报弹出窗口,但是当单击警报()弹出窗口的“确定”时,它消失了。

如何防止在弹出提示框点击“确定”后关闭模态框?

谢谢

【问题讨论】:

  • 请添加html

标签: javascript jquery html twitter-bootstrap


【解决方案1】:

您的模式正在关闭,因为您在.sendToUser 按钮上有data-dismiss="modal" 属性。删除此属性应防止模式关闭。

【讨论】:

【解决方案2】:

您需要在.sendToUser 元素中删除属性data-dismiss="modal"
如果需要关闭modal,只需要添加代码:

$('#userSelectionModal').modal('hide')

【讨论】:

    【解决方案3】:

    在你的脚本中使用

    window.location = "..\path after validation"
    

    同时避免在提交按钮中使用 data-dismiss="modal"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-22
      • 2015-09-26
      • 2018-09-06
      • 1970-01-01
      • 2014-01-02
      • 1970-01-01
      相关资源
      最近更新 更多