读写样式属性值

js读写样式
.style.只能行内样式 就是写在标签内的style=""内的样式属性---可写

IE中使用的是obj.currentStyle方法,
而FF是用的是getComputedStyle 方法
计算的样式值--只读,可通过.style方法写
即使行内没有显式的写出

 

function getDefaultStyle(obj,attribute){
// 返回最终样式函数,兼容IE和DOM,设置参数:元素对象、样式特性
return obj.currentStyle?obj.currentStyle[attribute]:document.defaultView.getComputedStyle(obj,false)[attribute];
}//属性名加引号

window.getComputedStyle(obj,false)[attribute];也行

obj.style.cssText 可读写

obj.style.cssText="width:30px;height:100px"

posted @ 2015-06-10 17:01  hello,w  阅读(124)  评论(0编辑  收藏  举报