包含错误的代码是:
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();
}, ...
})
稍后会在同一个文件中调用它:
function activateSliders() {
var slide_1 = new Slide('aCol', 'content');
var slide_2 = new SlideTwo('content', 'content2', 'content2-hider');
}
window.onload = activateSliders();
为什么Chrome(仅限Chrome)将$(triggers)
计算为NULL?
答案 0 :(得分:3)
根据我的经验,IE和FF倾向于偶尔慷慨地让jQuery代码很好地工作而不用将其封装在$(document).ready(
块中。尝试:
$(document).ready(function() {
activateSliders();
});