Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 手动隐藏后的引导模式错误_Javascript_Jquery_Twitter Bootstrap_Modal Dialog - Fatal编程技术网

Javascript 手动隐藏后的引导模式错误

Javascript 手动隐藏后的引导模式错误,javascript,jquery,twitter-bootstrap,modal-dialog,Javascript,Jquery,Twitter Bootstrap,Modal Dialog,我试图确保每次显示模式对话框时,都没有可见的对话框。为了做到这一点,我正在做: $('.modal').modal('hide'); 但这样做时,当我显示一个模态对话框时: var dlg_opts = { show: true, keyboard: false, backdrop: 'static' }; 如果单击背景(背景)或按escape键,模式将关闭。 当我删除.modal('hide')时,代码工作得很好,并且只能通过“close”按钮关闭modal 我的模式窗口有一个示例: &l

我试图确保每次显示模式对话框时,都没有可见的对话框。为了做到这一点,我正在做:

$('.modal').modal('hide');
但这样做时,当我显示一个模态对话框时:

var dlg_opts = { show: true, keyboard: false, backdrop: 'static' };
如果单击背景(背景)或按escape键,模式将关闭。 当我删除.modal('hide')时,代码工作得很好,并且只能通过“close”按钮关闭modal

我的模式窗口有一个示例:

<div class="modal fade" id="dlgWarning" tabindex="-1" role="dialog" aria-labelledby="dlgWarningLabel" 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">&times;</button>
                <h4 class="modal-title" id="dlgWarningLabel"></h4>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
                <button type="button" class="btn btn-warning" id="btnWarningAccept"></button>
            </div>
        </div>
    </div>
</div>
有人知道会是什么吗? 非常感谢

编辑:

您可以在这里进行测试:
如果尝试此操作,您将看到对话框在背景上以esc/单击的方式关闭。注释$('.modal').modal('hide'),代码运行良好

这是因为每次你想调用它时,你都会重新调用它

所以先初始化模态,不显示它们

Bootply

JS

var dlg_opts = { show: false, keyboard: false, backdrop: 'static' };  // <-- HERE
$('.modal').modal(dlg_opts);                 // <-- HERE

function ShowModal(id, width) {
    CloseModal();

    id = '#' + id;
    $(id).modal('show');       // <-- HERE

    if (arguments.length == 2) $(id).css('width', width + 'px');
}

function CloseModal() {
    $('.modal').modal('hide');
}

$(document).ready(function(){
  ShowModal('dlgWarning');
});

var dlg_opts={show:false,keyboard:false,background:'static'};//你的代码运行得很好,这是另外一回事。。。该对话框显示良好,但我需要该对话框只关闭“关闭”按钮。使用此代码,如果单击背景或按esc键,对话框将关闭。但是如果删除$('.modal').modal('hide'),代码工作得很好,对话框不会关闭。谢谢,我担心Bootstrap中有一个bug,我犯了一个错误总比框架人员犯了错误而痛苦要好
var dlg_opts = { show: false, keyboard: false, backdrop: 'static' };  // <-- HERE
$('.modal').modal(dlg_opts);                 // <-- HERE

function ShowModal(id, width) {
    CloseModal();

    id = '#' + id;
    $(id).modal('show');       // <-- HERE

    if (arguments.length == 2) $(id).css('width', width + 'px');
}

function CloseModal() {
    $('.modal').modal('hide');
}

$(document).ready(function(){
  ShowModal('dlgWarning');
});