所以我使用了一个 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 );