未捕获的TypeError:[对象窗口]没有方法'addEvent'

时间:2012-05-22 15:43:01

标签: javascript javascript-events

此脚本在http://jsfiddle.net/ByEzF/工作,但在停止工作的网站

<script type="text/javascript">
                var Add = {
                    setOptions: function(number) {
                        $('battle-options')
                        .removeClass('five-options')
                        .removeClass('four-options')
                        .removeClass('three-options')
                        .removeClass('two-options');

                        var option3 = $('option-3');
                        var option4 = $('option-4');
                        var option5 = $('option-5');

                        var versus3 = $('versus-3');
                        var versus4 = $('versus-4');
                        var versus5 = $('versus-5');

                        var elements5 = new Elements([option3, option4, option5, versus3, versus4, versus5]);
                        elements5.setStyle('display','none');

                        if(number == 5) {
                            $('battle-options').addClass('five-options');
                            elements5.setStyle('display','block');
                            $$('.battle-option input[type="file"]').set('size', 10);
                        } else if(number == 4) {
                            $('battle-options').addClass('four-options');
                            new Elements([option3, option4, versus3, versus4]).setStyle('display','block');
                            $$('.battle-option input[type="file"]').set('size', 15);
                        } else if(number == 3) {
                            $('battle-options').addClass('three-options');
                            new Elements([option3, versus3]).setStyle('display','block');
                            $$('.battle-option input[type="file"]').set('size', 19);
                        } else if(number == 2) {
                            $('battle-options').addClass('two-options');
                            $$('.battle-option input[type="file"]').set('size', 22);
                        }
                    }
                };

                window.addEvent('domready', function(){
                    Add.setOptions(2);
                });
            </script>

有错误消息

http://i.stack.imgur.com/7fi7G.png

未捕获的TypeError:[对象窗口]没有方法'addEvent'?

1 个答案:

答案 0 :(得分:4)

window.addEvent仅适用于MooTools(在jsfiddle页面上加载)。

http://mootools.net/docs/core/Element/Element.Event

来自文档:

  

注意:此方法也附加到文档和窗口。