function getStyle(elem,styleName){ if(elem.style[styleName]){//内联样式 return elem.style[styleName]; } else if(elem.currentStyle){//IE return elem.currentStyle[styleName]; } else if(document.defaultView && document.defaultView.getComputedStyle){//DOM styleName = styleName.replace(/([A-Z])/g,'-$1').toLowerCase(); var s = document.defaultView.getComputedStyle(elem,''); return s&&s.getPropertyValue(styleName); } else if(window.getComputedStyle){ styleName = styleName.replace(/([A-Z])/g,'-$1').toLowerCase(); var s = window.getComputedStyle(elem,''); return s&&s.getPropertyValue(styleName); } else{//other,for example, Safari return null; } }