未捕获的引用错误:未定义函数 [英] Uncaught reference error: Function not defined

查看:222
本文介绍了未捕获的引用错误:未定义函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些简单的代码用于我的第一个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() {

Demonstration

这篇关于未捕获的引用错误:未定义函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆