未捕获的引用错误:未定义函数 [英] Uncaught reference error: Function not defined
问题描述
我有一些简单的代码用于我的第一个jquery脚本之一,我试图调用它的函数,但它一直说该函数不存在!我已经检查了拼写,我确定我之前有这个工作,但我不知道发生了什么变化。
这是我的代码:
I have some simple code for one of my first jquery scripts, I'm trying to call it's function but it keeps saying the function doesn't exist! I have check the spelling and I'm sure I had this working before but I have no idea what's changed.
This is my code: http://jsfiddle.net/spadez/6LLpC/
This is how I'm calling my function:
jQuery(function($){
applyField();
});
Can anyone show me where I went wrong please?
applyField
isn't defined because jsFiddle wraps your code in an onload
event handler. So the function is only visible in this event handler.
Choose "no wrap - in <head>"
in the left menu :
Alternatively, you could also call your function from this event handler, this would be more coherent.
Note that calling the function isn't enough. If you want your event binding to be effective, change
$(this).on('change', '#apply',function() {
to
$(document.body).on('change', '#apply',function() {
这篇关于未捕获的引用错误:未定义函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!