Javascript 未捕获的引用错误:未定义函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7458153/
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
Uncaught Reference Error: function is not defined
提问by scotter
I'm working on an app for webOS that will take a megaupload link(assuming its a video), parse it into a direct link and stream it to a ffplay port for webos called TouchPlay. I'm working on a basic prototype that will just take the end code on a megaupload link and return a direct link. Now that I have laid out the basic parts of my application, on to my question. I want to take data in a form in an html page and feed it into a function in an external js script. Here's the html portion
我正在为 webOS 开发一个应用程序,它将采用 megaupload 链接(假设它是一个视频),将其解析为直接链接并将其流式传输到名为 TouchPlay 的 webos 的 ffplay 端口。我正在研究一个基本的原型,它只会在 megaupload 链接上获取结束代码并返回一个直接链接。现在我已经列出了我的应用程序的基本部分,接下来是我的问题。我想在 html 页面的表单中获取数据,并将其提供给外部 js 脚本中的函数。这是html部分
<html>
<head>
<script LANGUAGE="JavaScript" src="source/main.js"></script>
</head>
<body>
<form NAME="myform" ACTION="" METHOD="GET">
Enter the MegaUpload Code, ex. megaupload.com/?d=glgrn8f1 -> glgrn8f1: <BR>
<INPUT TYPE="text" NAME="inputbox" VALUE="">
<INPUT TYPE="button" NAME="button" Value="Click" onClick="javascript:codeIn(this.form);">
</form>
</body>
</html>
And in my main.js file is in a subdirectory called source and it contains function codeIn(code){
plus the rest of the functions.
在我的 main.js 文件中,它位于一个名为 source 的子目录中,它包含function codeIn(code){
其他功能。
Yet when I enter some test data in my web page and hit submit, I get an error in the chrome dev console saying Uncaught Reference Error: codeIn is not defined
然而,当我在我的网页中输入一些测试数据并点击提交时,我在 chrome 开发控制台中收到一个错误说 Uncaught Reference Error: codeIn is not defined
I have a very limited experience with html and javascript, but I cant seem to figure this out, I imagine its something really simple that I'm missing.
我对 html 和 javascript 的经验非常有限,但我似乎无法弄清楚这一点,我想它是我遗漏的非常简单的东西。
EDIT: Here's main.js, and yes, I have checked for typos. Just ask if you need to see the contents of any of these functions, but I didn't think they were neccesary.
编辑:这是 main.js,是的,我检查了拼写错误。只是问您是否需要查看这些函数中的任何一个的内容,但我认为它们不是必需的。
function codeIn(code){
...
}
function getInfo(url){
...
}
function waiting(timer){
...
}
Ive looked through all these suggestions and it all seems to point to a syntax error, yet when I try to put all the js functions into the head of the html, it works. So thats what I'm doing. I don't change a single thing when I reference it from source/main.js, but whatever.
我查看了所有这些建议,似乎都指向语法错误,但是当我尝试将所有 js 函数放入 html 的头部时,它起作用了。所以这就是我正在做的。当我从 source/main.js 引用它时,我不会改变任何东西,但无论如何。
回答by Saket
From the look of it, I think you then need to double check the location of main.js
. Verify whether your HTML file is in a location from where main.js can be accessed as source/main.js
, rather than something like ../source/main.js
(in case your HTML file is in a folder parallel/sibling to the source
folder)
从它的外观来看,我认为您需要仔细检查main.js
. 验证您的 HTML 文件是否位于可以作为 访问 main.js 的位置source/main.js
,而不是类似的位置../source/main.js
(如果您的 HTML 文件位于与该文件夹平行/同级的source
文件夹中)
回答by Jhenry
The RefereceError in general related to the scope of function that is present and the function call that is being made. It might the source path of the js, html/xhtml/jsp or function scope with in the js file. Hope this helps. Thanks.
RefereceError 通常与存在的函数范围和正在执行的函数调用有关。它可能是 js 文件中的 js、html/xhtml/jsp 或函数作用域的源路径。希望这可以帮助。谢谢。