开发者

Javascript works in FF and IE .. but Chrome says "cannot call method of null"!

The code that contains the error is:

var Slide = new Class({
    initialize: function(triggers, panels) {
        this.triggers = $(triggers).getElements('a[rel=content1-1]');
        this.panels = $(panels).getElements('ul[class=rel-content1-1]');
        this.active = -1;
        this.toggle();
    }, ...
})

This is called from later in the same file:

function activateSliders() {
    var slide_1 = new Slide('aCol', 'content');
    var slide_2 = new Slide开发者_Go百科Two('content', 'content2', 'content2-hider');
}
window.onload = activateSliders();

Why does Chrome -- and only Chrome -- calculate $(triggers) as NULL?


In my experience, IE and FF tend to be sporadically generous with letting jQuery code work nicely without it being encapsulated within a $(document).ready( block. Try:

$(document).ready(function() {
    activateSliders();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜