简体   繁体   English

Bootstrap Modal没有响应

[英]Bootstrap Modal not responding

I am using a modal that I used from a previous site where it works fine. 我使用的是以前工作正常的网站上使用的模式。 Difference is this modal will only appear in IE9 only to direct users to a better browser. 区别在于,此模式仅在IE9中出现,仅用于引导用户使用更好的浏览器。 I was able to test it with just a alert and works fine. 我能够仅通过警报对其进行测试,并且工作正常。

However, for some reason, when I transfer the code I did for a previous site to this new site, the Modal isn't responding and to one point is not showing on the site. 但是,由于某些原因,当我将以前站点的代码转移到该新站点时,Modal没有响应,并且一点都没有显示在该站点上。

When I try close the "Close" button, it will just refresh the page. 当我尝试关闭“关闭”按钮时,它只会刷新页面。 I am not sure why and when I close the "X" button, it does not work either. 我不确定为什么以及当我关闭“ X”按钮时,它也不起作用。

The code is inserted in a coldfusion file and I am not sure if it causing conflict or not. 该代码已插入Coldfusion文件中,我不确定是否会引起冲突。

Any help would be appreciated. 任何帮助,将不胜感激。

Here is what I did for the modal. 这是我为模态所做的。 ie-only detects whether it is IE9 or not: 即仅检测是否是IE9:

<!---<div class="ie-only" style="overflow-y:hidden;">
        <div class="modal fade in" id="myModal" aria-hidden="false" style="display:block; padding-right:17px;">
            <div class="modal-dialog modal-md custom-height-modal">
                <div class="modal-content">
                    <div class="modal-header" style="background-color:##428bca">
                        <button type="button" class="close" data-miss="modal">x</button>
                        <h3 class="modal-header" style="background-color:##428bca; text-align:center">Attention</h3>                        
                    </div><!---Modal-Header Div--->
                    <div class="modal-body">
                        <p style="text-align:center">You are using an outdated browser.<br /> <br /> <a href="http://browsehappy.com/">Upgrade your browser today</a> to better experience this site.</p>
                    </div><!---Modal-Body Div--->
                    <div class="modal-footer">
                        <p class="text-center"><a class="btn btn-default" data-dismiss="modal">Close</a></p>
                    </div><!---Modal-Footer Div--->
                </div><!---Modal-Content Div--->
            </div><!---Custom Height Div--->
        </div><!---Modal Fade in Div--->
    </div><!---Start of Modal Div--->               
    <!--End of Modal container--> --->
     <!---<script>
            $(function(){
                $('##myModal').modal('show');
            }
          </script>  
                <div class="modal-backdrop fade in"></div>--->

It looks like there is a syntax problem in your code: 您的代码中似乎存在语法问题:

$(function(){
  $('##myModal').modal('show');
}

This is incorrect; 这是不正确的。 it should be: 它应该是:

$(function(){
    $('#myModal').modal('show');
});

When corrected the Modal loads as a Modal, which in turn causes the Close button to operate as expected. 修正后,模态载荷将作为模态,这又将导致“关闭”按钮按预期运行。 Absent this the modal still loads (because you have in activated) but loads absent the overlay and absent the hook to Bootstrap's Modal JS which explains why your close button is non-functional. 缺少此功能的模态仍会加载(因为您已in激活状态),但会加载但缺少覆盖层,并且缺少Bootstrap的Modal JS的钩子,这说明了您的关闭按钮无法正常工作的原因。

You can see a functional example here: http://www.bootply.com/24IPYP8O3F 您可以在此处看到一个功能示例: http : //www.bootply.com/24IPYP8O3F

Why your code isn't working 为什么您的代码无法正常工作

The in class on your Modal div instructs Bootstrap to make that modal visible, and position it according to the Bootstrap CSS. Modal div上的in类指示Bootstrap使该模式可见,并根据Bootstrap CSS对其进行定位。 Your jQuery is wrong though, so Bootstrap treats this like a bit of HTML that is just part of the document. 但是您的jQuery是错误的,因此Bootstrap会将其视为只是文档一部分的HTML。

Once you correct your jQuery Bootstrap processes it as expected; 一旦您更正了jQuery Bootstrap即可按预期进行处理; as a Modal Javascript component. 作为Modal Javascript组件。 Once that happens it is presented with the overlay (as default) and the data-dismiss attributes are processed correctly. 一旦发生这种情况,它就会显示为叠加层(默认情况下),并且正确处理了data-dismiss属性。

The short of it is that the entire issue for why your Modal is not behaving like a Modal is that your jQuery is wrong. 简短的是,为什么您的Modal表现不像Modal的整个问题是jQuery是错误的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM