在寫js操作css的過程中發(fā)現(xiàn)float屬性在IE和firefox下對(duì)應(yīng)的js腳本是不一樣的,IE下對(duì)應(yīng)得是 styleFloat,firefox,chorme,safari下對(duì)應(yīng)的是cssFloat,可用in運(yùn)算符去檢測(cè)style是否包含此屬性。
LTFunction.setFloatStyle=function(obj,style)
{
var sty=obj.style;
if('cssFloat' in sty){
obj.style.cssFloat=style;
}else if('styleFloat' in sty){
obj.style.styleFloat=style;
}else{
throw 'set float style:'+style+'error.';
}
}