javascript 调用函数时“未捕获的类型错误:对象不是函数”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10713258/
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 TypeError: object is not a function" when calling a function
提问by Joshua
I am having this odd error with my code. I am trying to troubleshoot a page that [used] to work in Chrome but not in IE (suprise suprise) by adding specific triggers but now I am getting the Uncaught TypeError: object is not a function
error in Chrome's console.
我的代码有这个奇怪的错误。我正在尝试通过添加特定触发器来解决 [用于] 在 Chrome 中工作但不在 IE 中工作的页面(suprise suprise),但现在我Uncaught TypeError: object is not a function
在 Chrome 的控制台中收到错误消息。
As far as I can tell this is a function (work in progress):
据我所知,这是一个函数(正在进行中):
<script type="text/javascript">
function validate() {
var id = jQuery("form").attr('id');
var formid = "#"+id;
jQuery(formid).add("<input type=\"hidden\" name=\"APC_UPLOAD_PROGRESS\" value=\""+id+"\" />");
jQuery("#validate").hide();
jQuery("#submitme").show();
}
</script>
It is being called by the following code:
它由以下代码调用:
<button id="validate" onClick="validate()" type="button">Validate</button>
I am not using <input type="submit>
as I have extra form submit JS to run.
我没有使用,<input type="submit>
因为我有额外的表单提交 JS 来运行。
So when I click the button the page does nothing and I get titular said error in the console.
因此,当我单击该按钮时,该页面什么也不做,并且我在控制台中收到了名义上所说的错误。
I have tried using jQuery.fn.validate = function(){};
but to no avail.
我尝试使用jQuery.fn.validate = function(){};
但无济于事。
To make this more interesting, the site is Wordpress and this particular page loads jQuery and MooTools as well as have straight JS.
为了使这更有趣,该站点是 Wordpress,这个特定的页面加载了 jQuery 和 MooTools 以及直接的 JS。
In a nutshell; what silly little mistake have I made? All the searches on google are years old and generated by what I assume to be classes.
简而言之; 我犯了什么愚蠢的小错误?谷歌上的所有搜索都有多年历史,并且是由我假设的类生成的。
UPDATE
更新
The console says this line is the error
控制台说这一行是错误
<button id="validate" onClick="validate()" type="button">Validate</button>
UPDATE 2
更新 2
Pastbin link to the form code http://pastebin.com/3Kw5vdhn
Pastbin 链接到表单代码http://pastebin.com/3Kw5vdhn
采纳答案by HBP
In the Chrome browser you can ask that JS execution stops at an exception. To enable that, open the JS console and click on the small icon to the left of the moustaches between the main panel and the console. If the icon is blue you will stop execution on all exceptions, if red only on uncaught exceptions and if it is gray no stop at all.
在 Chrome 浏览器中,您可以要求 JS 执行在异常处停止。要启用它,请打开 JS 控制台并单击主面板和控制台之间胡须左侧的小图标。如果图标为蓝色,您将在所有异常时停止执行,如果红色仅在未捕获的异常时执行,如果为灰色则根本不停止。
So click until it is red to stop on uncaught exceptions. Run your web-page and executon should stop EXACTLY at the point the exception is raised. Then you can examine the value of the validate variable.
所以点击直到它变成红色以停止未捕获的异常。运行您的网页,执行程序应该在引发异常时完全停止。然后您可以检查验证变量的值。
I suspect it is some sort of global varaible clash between your code and other code you are loading. To check that quickly, rename validate something like QQvalidate and try your code.
我怀疑这是您的代码和您正在加载的其他代码之间的某种全局变量冲突。要快速检查,请重命名验证类似 QQvalidate 并尝试您的代码。
回答by MaxRecursion
Hi Joshua I tried running same code on my PC and its working perfectly, check your references (jQuery source file etc).
嗨约书亚我尝试在我的 PC 上运行相同的代码并且它运行良好,请检查您的参考资料(jQuery 源文件等)。