最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

uncaught typeerror undefined is not a function in javascript - Stack Overflow

programmeradmin4浏览0评论

The following function sets the following error: "uncaught typeerror undefined is not a function javascript" worked fine before , now fails =( Helpme please!

$('longitud-grados').addEvent('change', function(event){
        var lg = $('longitud-grados').value;
        var lm = $('longitud-minutos').value;
        var ls = $('longitud-segundos').value;

        if((lg > 117) || (lg < 86)) $('longitud-grados').value = '';

        if(lg != '' && lm != '' && ls != ''){
            c = new Coordenada();
            l = c.gms2dec(lg, lm, ls, 'w');
            $('longitud').value = l.decimal;
        }
    });

The following function sets the following error: "uncaught typeerror undefined is not a function javascript" worked fine before , now fails =( Helpme please!

$('longitud-grados').addEvent('change', function(event){
        var lg = $('longitud-grados').value;
        var lm = $('longitud-minutos').value;
        var ls = $('longitud-segundos').value;

        if((lg > 117) || (lg < 86)) $('longitud-grados').value = '';

        if(lg != '' && lm != '' && ls != ''){
            c = new Coordenada();
            l = c.gms2dec(lg, lm, ls, 'w');
            $('longitud').value = l.decimal;
        }
    });
Share Improve this question edited Nov 6, 2014 at 18:21 Alex K. 176k32 gold badges274 silver badges296 bronze badges asked Nov 6, 2014 at 17:06 LuigiLuigi 751 gold badge2 silver badges8 bronze badges 17
  • Am I correct in assuming that you're using MooTools?... – War10ck Commented Nov 6, 2014 at 17:08
  • What line does the error e from? – Matt R Commented Nov 6, 2014 at 17:09
  • Hi! marks the error in the line: $ ( 'longitud-grados' ). addEvent ( 'change' , function ( event ){ <-- uncaught TypeError: undefined is not a function – Luigi Commented Nov 6, 2014 at 17:12
  • 1 If that $ is jQuery, there's no "addEvent" method. – Pointy Commented Nov 6, 2014 at 17:15
  • 1 And what is the 'longitud-grados' selector? – Alex K. Commented Nov 6, 2014 at 17:15
 |  Show 12 more ments

1 Answer 1

Reset to default 3

this is because $ is not defined. I had a look at your web page

> $('longitud-grados').
Uncaught SyntaxError: Unexpected token } VM1196:732
> $('longitud-grados')
Uncaught TypeError: undefined is not a function VM1555:2
> $
undefined
> MooTools
Object {version: "1.4.5", build: "ab8ea8824dc3b24b6666867a2c4ed58ebb762cf0", More: Object, lang: Object}
> document.id
function (D,F,E){if(D&&D.$family&&D.uniqueNumber){return D;}var l=typeOf(D);return(e[l])?e[l](D,F,E||document):null;} 

So, for whatever reason, your $ is not defined - either do $ = document.id; or change your script to use document.id('longitud-grados');

you can also use a closure pattern around that code like

(function($){
    ...
    $('someid'); // will work
}(document.id));

keep in mind you also have jQuery on the page, doing $ = document.id may cause problems with your jQuery scripts if it's not using .noConflict() mode

发布评论

评论列表(0)

  1. 暂无评论