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 に答える