js动态调用css属性的小规律及实例说明

2022-01-14,,,,

本篇文章主要介绍了js动态调用css属性的小规律实例说明。需要的朋友可以过来参考下,希望对大家有所帮助

刚才看到一篇好的文章介绍js调用css属性,( ^_^ )不错嘛!免的自己忘记,总结一下

1、对于没有中划线的css属性一般直接使用style.属性名即可。

如:obj.style.margin,obj.style.width,obj.style.left,obj.style.position等。

2、对于含有中划线的css属性,将每个中划线去掉并将每个中划线后的第一个字符换成大写即可。

如:obj.style.marginTop,obj.style.borderLeftWidth,obj.style.zIndex,obj.style.fontFamily等。

因为float是Javascript的保留字,那怎么在js中书写样式表中的float呢?

我们不能直接使用obj.style.float来使用,这样操作是无效的。

其正确的使用方法是为:IE:obj.style.styleFloat,其他浏览器Mozilla(gecko),ff等用styleFloat:obj.style.cssFloat。

给个例子让大家好理解:
复制代码 代码如下:

this.style.float='left';  

alert(this.style.float);">测试1

 

if(this.style.cssFloat){this.style.cssFloat='left';  

}else{this.style.styleFloat='left';  

}alert(this.style.float);">测试2

 

以上就是js动态调用css属性的小规律及实例说明的详细内容,更多请关注本站其它相关文章!

《js动态调用css属性的小规律及实例说明.doc》

下载本文的Word格式文档,以方便收藏与打印。