Bootstrap模态不会出现

时间:2013-11-18 16:53:23

标签: jquery twitter-bootstrap modal-dialog

我的bootstrap(3.0.2)模式不会显示。我尝试了不同的按钮,链接和所有这些,但它根本不会出现。我感谢任何帮助!

<head>
    <link rel="stylesheet" href="css/bootstrap.min.css" />
</head>
<body>
    <button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#purchaseModal">Purchase</button>

    <div class="modal fade" id="purchaseModal" tabindex="-1" role="dialog" aria-labelledby="purchaseLabel" 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="purchaseLabel">Purchase</h4>
                </div>
                <div class="modal-body">
                    sup?
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Purchase</button>
                </div>
            </div>
        </div>
    </div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
    <script src="js/jquery-ui-1.10.3.custom.min.js"></script>
    <script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
</body>

更新1: 这是控制台中警告的屏幕截图。

enter image description here

更新2: 按钮和模态位于容器内。也许这有助于您找到解决方案的途径?

6 个答案:

答案 0 :(得分:2)

此代码工作正常。 你在某处有一个javaScript错误:

工作代码:

<!DOCTYPE html >

<html>
<head>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>    
    <!-- Bootstrap -->
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
    <!-- Optional theme -->
    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap-theme.min.css">
    <!-- Latest compiled and minified JavaScript -->
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>



</head>
<body>
    <button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#purchaseModal">Purchase</button>

    <div class="modal fade" id="purchaseModal" tabindex="-1" role="dialog" aria-labelledby="purchaseLabel" 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="purchaseLabel">Purchase</h4>
                </div>
                <div class="modal-body">
                    sup?
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Purchase</button>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

答案 1 :(得分:1)

我通过将这行JQuery添加到页面底部来解决这个问题;

<script>
    $("[data-toggle='modal']").modal();
</script>

答案 2 :(得分:1)

我认为你需要在你的html的头部放置jquery和bootstraps javascript文件路径。 我遇到了同样的问题,这对我有用。

<head>
    <link rel="stylesheet" href="plugins/bootstrap/css/bootstrap.css">
    <!-- put first the jquery path, otherwise the bootstrap.js won't work-->
    <script src="js/jquery/jquery-3.1.0.js"></script>
    <script src="plugins/bootstrap/js/bootstrap.min.js"></script>
</head>

希望它有效:)

答案 3 :(得分:0)

将这一行代码添加到头部解决了我的问题。

= javascript_include_tag 'application', 'data-turbolinks-track' => true

答案 4 :(得分:0)

我有同样的问题。当我添加此代码时:

let postBody = event.target.parentNode.parentNode.childNodes[1].textContent;

模态不会出现。当我删除它时,模态出现。

答案 5 :(得分:0)

如果我在 body 标签结束之前将下面的代码添加到 layout.html 的末尾,它开始对我有用。

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>