currentStyle和getComputedStyle的区别
currentStyle和getComputedStyle返回的都是字符串,比如返回的是“10px”。
currentStyle和getComputedStyle都为只读不可写,currentStyle仅支持IE,getComputedStyle支持除IE以外的浏览器,所以两者要一起使用。
function css(obj, attr) { if (obj.currentStyle) { return obj.currentStyle[attr]; } else { return getComputedStyle(obj, false)[attr]; } }
四种style总结: