[英]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">×</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.