简体   繁体   English

为什么不加载此外部JavaScript?

[英]Why doesn't this external JavaScript load?

I've been futzing with this for hours trying to figure out why codemirror.js won't load in any browser other than Firefox . 我已经花了好几个小时试图弄清楚为什么codemirror.js不能在除Firefox之外的任何其他浏览器中加载。 Any ideas? 有任何想法吗?

index.html index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
<head>
    <title></title> 
    <script src="CodeMirror/js/codemirror.js"></script> 

    <link href="Styles/Style.css" rel="stylesheet" type="text/css" />
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /> 

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> 
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> 

    <script type="text/javascript"> 
        $(document).ready(function () { $('#container-1').tabs(); });
    </script> 
    <style type="text/css"> /* (some css) */ </style>
</head><body>
<!-- (some stuff) -->
</body></html>

CodeMirror/js/codemirror.js CodeMirror / js / codemirror.js

alert("LOL");

I tried the code in Firefox 3.6.3, Internet Explorer 8, Opera 10.53 and Safari 4.0.5, and it works just fine. 我在Firefox 3.6.3,Internet Explorer 8,Opera 10.53和Safari 4.0.5中尝试了该代码,并且工作正常。

Note that the address to the script is relative, so if your page is at www.mydomain.com/content/pages/page.html , it will load the script from www.mydomain.com/content/pages/CodeMirror/js/codemirror.js , not www.mydomain.com/CodeMirror/js/codemirror.js . 请注意,脚本的地址是相对的,因此,如果您的页面位于www.mydomain.com/content/pages/page.html ,它将从www.mydomain.com/content/pages/CodeMirror/js/codemirror.js加载脚本www.mydomain.com/content/pages/CodeMirror/js/codemirror.js ,而不是www.mydomain.com/CodeMirror/js/codemirror.js

One thing that you can improve is to add the type attribute to the tag: 您可以改进的一件事是将type属性添加到标签:

<script src="CodeMirror/js/codemirror.js" type="text/javascript"></script>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM