Javascript files not working when linked, but work internally?

ぐ巨炮叔叔 提交于 2019-12-08 09:31:07

问题


I've never had a problem until recently, but for some reason when I link my JS files, they won't execute at all. jQuery works, but any files that require jQuery such as easing, and other concept files, they refuse to run in any browser on my machine.

But, here's the odd part. If I wrap all my code in 'script' tags within the HTML document, everything works fine; no issues, bugs, anything. (jquery.js is still linked to the document too).

I'm using Dreamweaver, which tells me they are correctly linked. I'm totally lost by this, I can't work it out.

Here's the HTML: http://jsbin.com/iyagub/1

I don't understand what could cause the JS files to not work.

I'm running it locally, but not on localhost, instead via Windows Explorer. I'm on Windows 8 64-bit. I'm not sure if this is a security issue, but I can't see how as I've said; it all worked fine before like any other project I've worked on.

Remember, if I paste any of the code from the linked JS files in to the HTML document directly with script tags, it works flawlessly.

Does anyone have any idea what it could be?


回答1:


In your JSBin example:

<script src="js/script.js" type="text/javascript"></script>
<script src="js/totop.js" type="text/javascript"></script>
<script src="js/easing.js" type="text/javascript"></script>
<script src="js/menu.js" type="text/javascript"></script>
<script src="js/jquery.js" type="text/javascript"></script>

Change the order to:

<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/totop.js" type="text/javascript"></script>
<script src="js/easing.js" type="text/javascript"></script>
<script src="js/menu.js" type="text/javascript"></script>
<script src="js/script.js" type="text/javascript"></script>

Your problem arises from jquery not being loaded into the document before other scripts try and use it.




回答2:


If you open your URL in a browser with an opened console: e.g. Firefox + firebug you will notice some of your scripts are failed to loading.

For example : http://jsbin.com/iyagub/js/easing.js is not found.

This could be due to many reason: Wrong paths? Wrong server configurations? A misplaced .htacces with bad Rewritecond -s ?



来源:https://stackoverflow.com/questions/13589844/javascript-files-not-working-when-linked-but-work-internally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!