简体   繁体   English

页面未协调外部js文件

[英]page does not reconize external js file

I have one html file that calls external js file. 我有一个HTML文件可以调用外部js文件。 I am presume html file does not reconize 我假设html文件未重新整理

external js file Since firebug throws error of 'myfunction() is not defined'. 外部js文件,因为Firebug抛出“未定义myfunction()的错误”。

Here is my code in external js file. 这是我的外部js文件中的代码。

function a(){
      //just function
} 

and here is html file that makes trouble. 这是造成麻烦的html文件。

<script type="javascript/text" src="./myjs.js"></script>
<script>
    a();
</script> 

can anybody tell me why I can't implement this simplest js file? 谁能告诉我为什么我不能实现这个最简单的js文件? when I run html file on python simpleHTTPServer, it even does not threw 404 error. 当我在python simpleHTTPServer上运行html文件时,它甚至没有引发404错误。
I am not sure what am I doing wrong here. 我不确定我在做什么错。

The (old) MIME type for JavaScript was text/javascript , not javascript/text . JavaScript的(旧)MIME类型是text/javascript ,而不是javascript/text

The browser will consider javascript/text to be an unknown scripting language and not execute it. 浏览器将把javascript/text视为未知脚本语言,而不执行它。

You appear to be using HTML 5 (since you are omitting the type attribute on the second script element). 您似乎正在使用HTML 5(因为您省略了第二个脚本元素的type属性)。 Omit it on all your script elements. 在所有脚本元素上忽略它。

Check with firebug or chrome debugger if your js file path is correct and if it's correctly loaded. 使用firebug或chrome调试器检查您的js文件路径是否正确以及是否正确加载。

You can see that in the "network" tab. 您可以在“网络”标签中看到。

The problem could be that my.js is not loaded when you accessed the function. 问题可能是您访问该函数时未加载my.js。 Try using the function in Firebug or something. 尝试在Firebug中使用该功能。

It works for me. 这个对我有用。 There must be something wrong with your path or your JS-File! 您的路径或JS文件肯定有问题!

我无法从js文件加载该函数,因为该函数本身有错误。

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

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