Jquery Modal出现但阻止了网站

时间:2017-03-01 15:07:15

标签: javascript jquery

我关注this tutorial。我想做同样的事情,但使用链接而不是按钮。它显示模态但整个页面变暗并被阻挡。我不确定我做错了什么。

$( "#openModal" ).click(function() {
 $("#myModal").modal();
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

<script src="/assets/admin/js/myjavascript.js"></script>

   <a id="openModal">Open Modal</a> <!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Modal Header</h4>
            </div>
            <div class="modal-body">
                <p>Some text in the modal.</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>

    </div>
</div>

1 个答案:

答案 0 :(得分:1)

要使用bootstrap模式,您需要:

对于css:

<link rel="stylesheet" 
      href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />

对于jquery:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

在剧本中:

$( "#openModal" ).click(function() {
 $("#myModal").modal();
});

如果没有参考,它将无法运作:

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

注意:版本可以更改。