由于IE8不支持getComputedStyle,我们只能使用currentStyle.但是,它不会返回某些属性的实际"计算"值.
例如:
<style type="text/css">
#div {/* no properties are defined here */}
</style>
Run Code Online (Sandbox Code Playgroud)
<div id="div">div</div>
Run Code Online (Sandbox Code Playgroud)
// returns "medium" instead of 0px
document.getElementById('div').currentStyle.borderLeftWidth
// returns "auto" instead of 0px
document.getElementById('div').currentStyle.marginLeft
// returns "undefined" instead of 1
document.getElementById('div').currentStyle.opacity
Run Code Online (Sandbox Code Playgroud)
有没有人在不使用jQuery或其他Javascript库的情况下为所有属性提供跨浏览器解决方案?