Bootstrap 3 模式示例代码 Window 不工作

Bootstrap 3 Example Code for Modal Window Not working

这个问题简单到让人尴尬。作为测试,我将 http://getbootstrap.com/javascript/#modals 中的代码直接复制到一个仅包含基本页面设置的页面中,但它不起作用。这意味着我正在做一些非常愚蠢的事情。这是我的整个页面:

<!DOCTYPE html>

<html>
    <head>

        <!-- Website Title & Description for Search Engine purposes -->
        <title></title>
        <meta name="description" content="">

        <!-- Mobile viewport optimized -->
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

        <!-- Bootstrap CSS -->
        <link href="includes/css/bootstrap.css" rel="stylesheet">
        <link href="includes/css/bootstrap-glyphicons.css" rel="stylesheet">

        <!-- Custom CSS -->
        <link href="includes/css/styles.css" rel="stylesheet">

        <!-- Include Modernizr in the head, before any other Javascript -->
        <script src="includes/js/modernizr-2.6.2.min.js"></script>

    </head>
    <body>

    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Open modal for @mdo</button>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@fat">Open modal for @fat</button>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@getbootstrap">Open modal for @getbootstrap</button>
...more buttons...

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <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="exampleModalLabel">New message</h4>
      </div>
      <div class="modal-body">
        <form>
          <div class="form-group">
            <label for="recipient-name" class="control-label">Recipient:</label>
            <input type="text" class="form-control" id="recipient-name">
          </div>
          <div class="form-group">
            <label for="message-text" class="control-label">Message:</label>
            <textarea class="form-control" id="message-text"></textarea>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Send message</button>
      </div>
    </div>
  </div>
</div>


    <!-- All Javascript at the bottom of the page for faster page loading -->

    <!-- First try for the online version of jQuery-->
    <script src="http://code.jquery.com/jquery.js"></script>

    <!-- If no online access, fallback to our hardcoded version of jQuery -->
    <script>window.jQuery || document.write('<script src="includes/js/jquery-1.8.2.min.js"><\/script>')</script>

    <!-- Bootstrap JS -->
    <script src="includes/js/bootstrap.js"></script>

    <!-- Custom JS -->
    <script src="includes/js/script.js"></script>


<script type="text/javascript"> 
$('#exampleModal').on('show.bs.modal', function (event) {
  var button = $(event.relatedTarget) // Button that triggered the modal
  var recipient = button.data('whatever') // Extract info from data-* attributes
  // If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
  // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
  var modal = $(this)
  modal.find('.modal-title').text('New message to ' + recipient)
  modal.find('.modal-body input').val(recipient)
})
</script>   


</body>
</html>

然而,当我按下按钮时,模式启动了,但我得到的不是 "New Message to @mdo",就像你在他们的网站上看到的那样,而是 "New Message to undefined"。我错过了什么?

     var recipient = button.data('whatever')

button.data('whatever') 未定义

首先这并不尴尬,我们在那里。其次,您的代码对我来说看起来不错。唯一吸引我的是这一行:

<script src="includes/js/bootstrap.js"></script>

这个目录存在吗?因为如果您从网站上复制它,它可能指的是存储在服务器中的文件。尝试包括 bootstrap.js 你自己。 css 文件也一样

哦,天哪。问题(显然)从来都不是代码。它与我加载的 JQuery 或 Bootstrap 版本一起使用。当我用指向源的链接替换我的本地副本时,问题就消失了。我很高兴我发现了这个问题,否则它会在我开发它时遍及我的整个站点。感谢大家的帮助。我猜你在成为专家之前必须学习愚蠢的东西。