a的结果getComputedStyle包含一个名为"margin"的属性,但该属性""在Mozilla Firefox或Apple Safari中始终为空字符串(); 但是,在Internet Explorer(和Google Chrome)中,margin属性包含预期值(即使在IE 6中).使用getPropertyValue("margin")返回对象的方法时返回相同的结果.
如何在Firefox和Safari中获得保证金的计算值?
var el = document.body.appendChild(document.createElement('div'));
el.style.margin = '2px';
console.log(getComputedStyle(el, null).margin === ""); // false in IE and Chrome
console.log(getComputedStyle(el, null).getPropertyValue("margin") === ""); // sameRun Code Online (Sandbox Code Playgroud)
javascript ×1