论坛首页 Web前端技术论坛

js操作css float属性

浏览 2544 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-08-31   最后修改:2009-09-01

在写js操作css的过程中发现float属性在IE和firefox下对应的js脚本是不一样的,IE下对应得是styleFloat,firefox,chorme,safari下对应的是cssFloat,可用in运算符去检测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.';
	}
}
 

 

参考:

https://developer.mozilla.org/en/CSS/float

http://msdn.microsoft.com/en-us/library/ms530755%28VS.85%29.aspx

论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics