【发布时间】:2013-03-22 16:11:58
【问题描述】:
我拼凑了一些工作了几年的 mootools 手风琴代码,但突然间我注意到 Firefox 破坏了它——在 safari、chrome 或 IE 中没有问题。
控制台显示:TypeError: toggler is undefined here:
toggler.setStyle('color', '#666');
我想这很简单,但是对于这个新手,我不知道是怎么回事?有什么帮助吗?完整代码如下:
window.addEvent('domready', function() {
var myAccordion = new Accordion($('accordion'), 'h1.toggler', 'div.element', {
display: -1,
opacity: true,
alwaysHide: true,
onActive: function(toggler, element){
toggler.setStyle('color', '#df1a00');
//remove the toggler hover events to clear out its events when it was inactive
toggler.removeEvents('mouseenter');
toggler.removeEvents('mouseleave');
//then add your events again
toggler.addEvent('mouseenter',function()
{
//...
});
},
onBackground: function(toggler, element){
toggler.setStyle('color', '#666');
//remove the toggler hover events to clear out its events when it was active
toggler.removeEvents('mouseenter');
toggler.removeEvents('mouseleave');
//then add your events again
toggler.addEvent('mouseenter',function()
{this.setStyle('color', '#df1a00');
toggler.addEvent('mouseleave',function()
{this.setStyle('color', '#666');
});
});
}
});
var myAccordion2 = new Accordion($('accordion2'), 'h4.toggler', 'div.element2', { 显示:-1, 不透明度:真实, 总是隐藏:真的, onActive:函数(切换器,元素){ toggler.setStyle('color', '#df1a00');
//remove the toggler hover events to clear out its events when it was inactive
toggler.removeEvents('mouseenter');
toggler.removeEvents('mouseleave');
//then add your events again
toggler.addEvent('mouseenter',function()
{
//...
});
},
onBackground: function(toggler, element){
toggler.setStyle('color', '#666');
//remove the toggler hover events to clear out its events when it was active
toggler.removeEvents('mouseenter');
toggler.removeEvents('mouseleave');
//then add your events again
toggler.addEvent('mouseenter',function()
{this.setStyle('color', '#df1a00');
toggler.addEvent('mouseleave',function()
{this.setStyle('color', '#666');
});
});
}
});
var myAccordion = new Accordion($('accordion3'), 'h5.toggler', 'div.element3', {
display: -1,
opacity: true,
alwaysHide: true,
onActive: function(toggler, element){
toggler.setStyle('color', '#df1a00');
//remove the toggler hover events to clear out its events when it was inactive
toggler.removeEvents('mouseenter');
toggler.removeEvents('mouseleave');
//then add your events again
toggler.addEvent('mouseenter',function()
{
//...
});
},
onBackground: function(toggler, element){
toggler.setStyle('color', '#666');
//remove the toggler hover events to clear out its events when it was active
toggler.removeEvents('mouseenter');
toggler.removeEvents('mouseleave');
//then add your events again
toggler.addEvent('mouseenter',function()
{this.setStyle('color', '#df1a00');
toggler.addEvent('mouseleave',function()
{this.setStyle('color', '#666');
});
});
}
});
});
【问题讨论】: