jquery – Bootstrap:TypeError:$(…).modal不是函数

前端之家收集整理的这篇文章主要介绍了jquery – Bootstrap:TypeError:$(…).modal不是函数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在尝试从 jquery调用bootstrap模式并继续收到此错误消息:
TypeError: $(...).modal is not a function

这是我的代码

<button id="btnTest" class="btn btn-default">Show Modal</button>
<div id="dummyModal" role="dialog" class="modal fade">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" data-dismiss="modal" class="close">&times;</button>
          <h4 class="modal-title">Error</h4>
        </div>
        <div class="modal-body">
          <p>Quick Brown Fox Jumps Over The Lazy Dog</p>
        </div>
        <div class="modal-footer">
          <button type="button" data-dismiss="modal" class="btn btn-default">Close</button>
        </div>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript" src="/js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="/js/bootstrap.js"></script>
<script type="text/javascript">
  $('document').ready(function () {
    $('#btnTest').click(function () {
        $('#dummyModal').modal('show');
    });
  });
</script>

仅供参考,我使用bootstrap 3.3.5和jquery 1.11.3.我试过jQuery.noConflict();等等从this thread开始,但仍然没有运气.这是complete code

解决方法

用这个.
它会工作.
我使用了bootstrap 3.3.5和jquery 1.11.3
$('document').ready(function() {
  $('#btnTest').click(function() {
    $('#dummyModal').modal('show');
  });
});
body {
  background-color: #eee;
  padding-top: 40px;
  padding-bottom: 40px;
}
<!DOCTYPE html>
<html>

<head>
  <Meta charset="utf8">
  <Meta http-equiv="X-UA-Compatible" content="IE=edge">
  <Meta name="viewport" content="width=device-width,initial-scale=1">
  <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <title>Modal Test</title>
</head>

<body>
  <div class="container">
    <button id="btnTest" class="btn btn-default">Show Modal</button>
    <div id="dummyModal" role="dialog" class="modal fade">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" data-dismiss="modal" class="close">&times;</button>
            <h4 class="modal-title">Error</h4>
          </div>
          <div class="modal-body">
            <p>Quick Brown Fox Jumps Over The Lazy Dog</p>
          </div>
          <div class="modal-footer">
            <button type="button" data-dismiss="modal" class="btn btn-default">Close</button>
          </div>
        </div>
      </div>
    </div>
  </div>
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
  <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</body>

</html>
原文链接:https://www.f2er.com/jquery/178768.html

猜你在找的jQuery相关文章