Bootstrap模式弹出窗口无法正常工作

时间:2015-11-19 12:03:52

标签: javascript jquery html html5 bootstrap-modal

我有一个简单的HTML文件,我想在其中显示Bootstrap模式弹出窗口。以下是此代码。

.js文件:

 <meta name="viewport" content="width=device-width, initial-scale=1">
     <link rel="stylesheet" href="/po_ritesh/css/bootstrap.min.css">

    <script type="text/javascript" src="//code.jquery.com/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/1.10.9/js/dataTables.bootstrap.min.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>


    <link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.9/css/dataTables.bootstrap.min.css">

    <link rel="stylesheet" type="text/css" href="./css/home.css">
    <script src="./js/global.js"></script>
    <script src="./js/home.js"></script>

按钮控制:

 <button class="myBtn" type="button" data-toggle="modal" data-target="#myModal">test </button>

模态div:

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title" id="myModalLabel">Modal title</h4>
                        </div>
                        <div class="modal-body">
                            test
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                            <button type="button" class="btn btn-primary">Save changes</button>
                        </div>
                    </div>
                </div>
            </div>

3 个答案:

答案 0 :(得分:2)

你必须在jQuery.js之后包含bootstrap.min.js

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script>

答案 1 :(得分:1)

您的代码中没有包含bootstrap.js.

答案 2 :(得分:1)

您有两个问题:

  1. 您错过了一个图书馆,bootstrap.js
  2. 您的JavaScript文件以错误的顺序引用,导致JavaScript错误。此错误会阻止您的浏览器运行其他脚本,并且模式代码不起作用。
  3. 试试这个:

    <script type="text/javascript" src="//code.jquery.com/jquery-1.11.3.min.js"></script>
    
    <!-- this file was missing -->
    <script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    
    <script type="text/javascript" src="https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
    
    <!-- this file was moved after the jQuery Datatables library was laoded -->
    <script type="text/javascript" src="https://cdn.datatables.net/1.10.9/js/dataTables.bootstrap.min.js"></script>