0

所以我使用了一个 jQuery 插件的模板,不幸的是它不能在 IE8 和 IE 兼容模式下工作。

我不确定我写它们的方式是否完全兼容,或者我只是错过了什么?

HTML:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>SuperHero Demo</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="Scripts/SuperSelect.js"></script>
</head>

<body>

<div class="test" style="border:1px solid #000;">
<p>Hello World!</p>
</div>
<div>
<p>Sup World</p>
</div>

<script>
$('.test').superHero({

});
</script>
</body>
</html>

脚本:

// Utility
if ( typeof Object.create !== 'function' ) {
    Object.create = function( obj ) {
        function F(){};
        F.prototype = obj;
        return new F();
    };
}

(function( $, window, document, undefined ) {

    var Super = {
        init: function( options, elem ) {
            var self = this;

            self.elem = elem;
            self.$elem = $( elem );

            if ( typeof options === 'string' ) {
                self.duration = options;
            } else {
                // object was passed
                self.duration = options.duration;
            }                       

            self.options = $.extend({}, $.fn.superHero.options, options );

            self.replaceSelect();

        },

        replaceSelect: function( duration ) {
            var self = this;
            $('.test').hide();
            $('.test').after('<select><option value="volvo">Volvo</option><option value="saab">Saab</option><option value="mercedes">Mercedes</option><option value="audi">Audi</option></select>');

        },


    };

    $.fn.superHero = function( options ){
        return this.each(function() {
            var hero = Object.create( Super );

            hero.init( options, this );

            $.data( this, 'superHero', hero);

        });

    };

    $.fn.superHero.options = {
        duration:           5000,   //Milliseconds that each slide remains on screen. Default is 5 seconds.
        transition:         'fade', //How will the slides trascend?
    };

})( jQuery, window, document );

http://jsfiddle.net/userdude/QWhPL/1/

4

1 回答 1

3

看起来当您设置选项时,在转换属性之后有一个尾随逗号。IE8 不喜欢尾随逗号,请将其更新为:

$.fn.superHero.options = {
        duration:           5000,   //Milliseconds that each slide remains on screen. Default is 5 seconds.
        transition:         'fade' //How will the slides trascend?
    };

...它应该工作。

在需要删除的 replaceSelect: 函数声明之后还有一个尾随逗号:

replaceSelect: function( duration ) {
            var self = this;
            $('.test').hide();
            $('.test').after('<select><option value="volvo">Volvo</option><option value="saab">Saab</option><option value="mercedes">Mercedes</option><option value="audi">Audi</option></select>');

        }
于 2012-06-15T13:15:35.490 回答