var box=document.getElementById('box');
function getCss(curEle,attr){
var val=null;
//去单位
var reg=/^(-?d+(.d+)?)([pt|px|em|rem])?$/i;
if("getComputedStyle" in window){//window.getComputedStyle
val=window.getComputedStyle(curEle,null)[attr];
}else{//ie6,7,8
if(attr==="opacity"){
reg=/^alpha(opacity=(d+(?:.d+)?))$/;
val=reg.test(val)?reg.exec(attr)[1]/100:1;
}else{
val=curEle.currentStyle[attr];
}
}
return reg.test(val)?parseFloat(val):val;
}
console.log(getCss(box,'margin'));
console.log(getCss(box,'float'));
console.log(getCss(box,'position'));
console.log(getCss(box,'opacity'));