admin管理员组文章数量:1432196
I have small bug (I suppose) in my Javascript file. It is simple file but it is not working as expected on Firefox 6 (on Chrome it is working fine). Everything is working except submit(), and validate() is working only when called within document.ready, if I try to access these functions directly, I get...
uncaught exception: ReferenceError: (function) is not defined
Here is the JS file .php?i=CMy4WYPF, it is loaded after jQuery lib, there are no other JS files.
Thank you very much for your help.
I have small bug (I suppose) in my Javascript file. It is simple file but it is not working as expected on Firefox 6 (on Chrome it is working fine). Everything is working except submit(), and validate() is working only when called within document.ready, if I try to access these functions directly, I get...
uncaught exception: ReferenceError: (function) is not defined
Here is the JS file http://pastebin./raw.php?i=CMy4WYPF, it is loaded after jQuery lib, there are no other JS files.
Thank you very much for your help.
Share Improve this question asked Jul 22, 2011 at 9:50 Dejan MarjanovićDejan Marjanović 19.4k7 gold badges53 silver badges67 bronze badges2 Answers
Reset to default 3You don't show how or when the code is loaded, so when it is executed is unknown.
The document markup is not provided so it is impossible to tell what may or may not work, or why. Here are some suggestions for improvements, they may or may not make any difference.
The following statements:
> var exception = $('#teligence-exception');
> var form = $('#teligence-ctc form');
are at the top of the script. Do the elements referenced by the IDs exist in the DOM when the statements are executed?
Searching for codes in an array using jQuery's inArray is inefficient in browsers that lack a native Array.prototype.indexOf method (which is quite a few). Far better to have codes as a string with a delimiter and use the ubiquitous String.prototype.indexOf() method, e.g.
var codes = '|201|202|203|';
...
var x = code.indexOf('|' + val + '|');
The submit function is not called in the posted code.
Much of the script appears very inefficient:
> var val = $(this).val();
> $(this).val( val.replace(/[^0-9]/, '') );
can be
var val = this.value;
this.value = val.replace(/D/g, '');
note that in the original code, only the first non-digit character will be replaced. In the suggested code, all non-digit characters will be replaced (courtesy of the g flag).
Also:
validate($(this).attr('name'));
can be:
validate(this.value);
And so on. The idea is to not create unnecessary jQuery objects.
Dont forget to include ,
<script src="jquery-1.xx.x.min.js" type="text/javascript"> </script>
if you are using jquery, xx-x stand for the
本文标签: javascriptReferenceError function is not definedStack Overflow
版权声明:本文标题:javascript - ReferenceError: function is not defined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745587867a2665018.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论