$(window).load(function(){
alert(typeof $.fn.init_deps);
});
$(document).ready(function()开发者_Python百科{
/* Departments switcher */
$.fn.init_deps = function(s){
var o = {
deps:false,
cats:false
}
$.extend(o,s);
if(!s.deps || !s.cats) {return;}
return this.each(function(){
var select = $('<select id="department" name="department"></select>')
.appendTo(this)
.departments(s)
.change(function(){
var select = $('select#category');
select.categories({cats:s.cats,current_dep:$(this).val()});
var p_width = select.parent().outerWidth();
var ch_width = select.outerWidth();
select.parent().css('width',p_width+'px')
.find('select').css('width',(ch_width + 8)+'px')
.parent().find('span').css('width',(p_width - 20)+'px');
$.uniform.update(select);
});
var p_width = select.parent().outerWidth();
var ch_width = select.outerWidth();
select.uniform({selectClass:'selector uni1'})
.parent().css('width',p_width+'px')
.find('select').css('width',(ch_width + 8)+'px')
.parent().find('span').css('width',(p_width - 20)+'px');
});
}
});
Alert returns undefined in IE7, but in all other browsers it returns function.
Help, can't figure out where is problem.
window onload probably fires before the function is bound in IE. You should define the $.fn before document ready.
$(window).load(function(){
alert(typeof $.fn.init_deps);
});
(function($){
$.fn.init_deps = function(s){
var o = {
deps:false,
cats:false
}
$.extend(o,s);
if(!s.deps || !s.cats) {return;}
return this.each(function(){
var select = $('<select id="department" name="department"></select>')
.appendTo(this)
.departments(s)
.change(function(){
var select = $('select#category');
select.categories({cats:s.cats,current_dep:$(this).val()});
var p_width = select.parent().outerWidth();
var ch_width = select.outerWidth();
select.parent().css('width',p_width+'px')
.find('select').css('width',(ch_width + 8)+'px')
.parent().find('span').css('width',(p_width - 20)+'px');
$.uniform.update(select);
});
var p_width = select.parent().outerWidth();
var ch_width = select.outerWidth();
select.uniform({selectClass:'selector uni1'})
.parent().css('width',p_width+'px')
.find('select').css('width',(ch_width + 8)+'px')
.parent().find('span').css('width',(p_width - 20)+'px');
});
}
})(jQuery);
$document.ready works differently in different browsers. In IE it will bind to windows onload
window.attachEvent( "onload", jQuery.ready );
Therefore you can't count on code in a document.ready block to run before an onload block.
精彩评论