简体   繁体   English

为什么我的引导JavaScript无法在本地运行?

[英]Why won't my bootstrap javascript run locally?

So I thought I'd give you my code to explain what my issue is.. 所以我想我会给你我的代码来解释我的问题是..

<!DOCTYPE html>
<html>
<head>
<title>User Guide</title>
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
</head>
<body>

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
 </button>

<!-- Modal -->
<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">
    ...
  </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>
<footer>
    <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
    <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>
    <script src="modal.js"></script>
</footer>
</body>
</html>

There it is. 在那里。 but for some reason, the bootstrap js script isn't running so when I click the button nothing is happening... 但是由于某种原因,bootstrap js脚本没有运行,所以当我单击按钮时,什么也没有发生...

anybody able to give me a hand? 有人可以帮我吗?

Thanks, Jonathan 谢谢乔纳森

It's because you're using a protocol-relative URL for jQuery. 这是因为您正在使用jQuery的协议相对URL。 You should be seeing errors in the browser's console. 您应该在浏览器的控制台中看到错误。

Try changing: 尝试更改:

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>

to: 至:

<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>

When you open a file locally in your browser (outside of a web server) most browser's will use the file:// protocol, so //code.jquery.com/jquery-1.11.3.min.js becomes file://code.jquery.com/jquery-1.11.3.min.js and odds are that you don't have jQuery that location. 当您在浏览器中(在Web服务器外部)在本地打开文件时,大多数浏览器将使用file://协议,因此//code.jquery.com/jquery-1.11.3.min.js变为file://code.jquery.com/jquery-1.11.3.min.js ,奇怪的是您没有jQuery所在的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的JavaScript函数无法运行? - Why won't my javascript function run? 为什么我的php文件不能从我的javascript运行? - Why won't my php file run from my javascript? 尝试在手风琴下拉列表中更改+/-图标,但Javascript文件似乎不会在我的HTML中本地加载。 (Bootstrap 4) - Attempting a +/- icon change on accordion dropdown, but the Javascript file won't seem to load locally in my HTML. (Bootstrap 4) 我的引导程序模式在本地运行时有效,但是通过git-hub运行时无法打开? - My bootstrap modal is working when i run it locally, but it won't open when i run it through git-hub? 为什么我的 JavaScript 不能在 HTML Visual Code 中运行 - Why won't my JavaScript run in HTML Visual Code 为什么 Vercel 不运行我在 HTML 中链接的 JavaScript 代码 - Why won't Vercel run my JavaScript code linked in HTML 为什么我的Javascript无法在WordPress上运行,但是在本地HTML上可以正常运行? - Why won't my javascript work on WordPress but fine when doing locally HTML? 为什么我的货币换算javascript程序无法运行? - Why won't my currency conversion javascript program won't run? 为什么不运行Javascript代码? - Why won't Javascript code run? 为什么我的jQuery代码不会运行? - Why won't my jQuery code run?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM