【问题标题】:firefox only: TypeError: toggler is undefined仅限火狐:TypeError:切换器未定义
【发布时间】:2013-03-22 16:11:58
【问题描述】:

我拼凑了一些工作了几年的 mootools 手风琴代码,但突然间我注意到 Firefox 破坏了它——在 safari、chrome 或 IE 中没有问题。

http://jordanrossfilms.com

控制台显示: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');

        });

        });
    }

});

});

【问题讨论】:

    标签: mootools accordion


    【解决方案1】:

    我看到你正在使用 mootools 1.2 mootools 最近发布了对 1.2 的修复,导致 firefox 出现错误,因为新的 firefox 和 mootools 与 String.concat 发生冲突。

    你可以看到一个Blog Post 关于它。 无论如何尝试更新到新的1.2版本,看看它是否解决了问题

    【讨论】:

    • 刚刚尝试过,网站在所有浏览器中都完全中断。 Firefox 显示此错误: ReferenceError: Accordion is not defined ReferenceError: Accordion is not defined var myAccordion = new Accordion($('accordion'), 'h1.toggler', 'div.element', {
    • 手风琴在 mootools more http://mootools.net/more125 中定义。你也下载了吗?检查以前在 mootools 和 dl 中使用的所有内容
    • 是的!感谢那。添加了更多的所有元素,它又可以工作了。
    • 我很高兴得到分数然后^^
    • 试图投票给你,但我的声誉还不够!不过检查了你的答案。再次感谢。
    猜你喜欢
    • 1970-01-01
    • 2016-07-03
    • 1970-01-01
    • 1970-01-01
    • 2015-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多