function getTrueStyle(obj,attr){ if(obj.currentStyle){ //ie return obj.currentStyle[attr]; } else{ return window.getComputedStyle(obj, null)[attr] || document.defaultView.getComputedStyle(obj,null)[attr]; } }
var limarginLeft=parseInt(/d+/.exec(getTrueStyle(firstli,"marginLeft")));//左margin var limarginRight=parseInt(/d+/.exec(getTrueStyle(firstli,"marginRight")));//右margin var lirealwidth=limarginLeft+firstli.offsetWidth+limarginRight;//真实宽度
代码中的正则是用来取“10px”中的“10”