javascript 脚本文件未加载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19214276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Script file not loading
提问by Blanky
I am beating my head against the wall on this. I know Javascript/jQuery well and I can not see the reason why this is not working. I've tried both 2.0.3 and 1.10.2 with the same results.
我正在用头撞墙。我很了解 Javascript/jQuery,但我看不出这不起作用的原因。我已经尝试了 2.0.3 和 1.10.2,结果相同。
I'm trying to just do a test to make sure the script file is loaded. I've tried a number of different methods, nothing is working. But when I click the url in the source, it goes to the correct file that has the right code.
我正在尝试进行测试以确保加载了脚本文件。我尝试了许多不同的方法,没有任何效果。但是,当我单击源中的 url 时,它会转到具有正确代码的正确文件。
This is all I'm trying to do.
这就是我正在尝试做的所有事情。
$(document).ready(function() {
alert('test');
});
Which works if I include it in the page between <script>
tags. But not when referencing it from a .js
file.
如果我将它包含在<script>
标签之间的页面中,这会起作用。但不是从.js
文件中引用它时。
This is how I'm loading it:
这是我加载它的方式:
<script type="text/javscript"
src="http://localhost/kdev/views/dashboard/js/default.js"></script>
Clicking on that url takes me to the correct file with the alert above.
单击该 url 会将我带到带有上述警报的正确文件。
But's not working. What the crap is going on? What did I forget? Do I have a typo?
但不工作。这是怎么回事?我忘记了什么?我有错别字吗?
The entire page:
整个页面:
<!doctype html>
<html>
<head>
<title>Test</title>
<link rel="stylesheet" href="http://localhost/kdev/public/css/default.css" />
<script type="text/javscript"
src="http://localhost/kdev/public/js/jquery-2.0.3.min.js"></script>
<script type="text/javscript"
src="http://localhost/kdev/views/dashboard/js/default.js"></script>
</head>
<body>
<div id="header">
header
<br />
<a href="http://localhost/kdev/index">Index</a>
<a href="http://localhost/kdev/help">help</a>
<a href="http://localhost/kdev/dashboard/logout">logout</a>
</div>
<div id="content">
Dashboard... logged in only </div>
<div id="footer">feet</div>
</body>
</html>
回答by Dvir
Change this (You missed 'a' char in 'javascript')
改变这个(你错过了“javascript”中的“a”字符)
<script type="text/javscript"
src="http://localhost/kdev/views/dashboard/js/default.js"></script>
to this:
对此:
<script type="text/javascript"
src="http://localhost/kdev/views/dashboard/js/default.js"></script>
回答by Chris Happy
My lightbox script file wasn't loeading properly:
我的灯箱脚本文件没有正确加载:
<script type="text/javascript" src="js/lightbox-plus-jquery.min.js"></script>
I then removed type="text/javascript"
and it loaded perfectly.
然后我将其删除type="text/javascript"
并完美加载。