我的理解是anchor tag is inline by default 。那么为什么下面的代码会返回这些意外的结果呢?
var aTag = document.createElement('A');
document.defaultView.getComputedStyle(aTag).display
// Chrome: ""
// Firefox: "block"
我错过了什么?
最佳答案
除非您将 anchor 放入 DOM 中,否则它没有计算样式,因为浏览器 native 样式表尚未应用
var aTag = document.createElement('a');
document.body.appendChild(aTag);
var d = window.getComputedStyle(aTag).display;
// now returns inline in chrome
关于javascript - 为什么 `getComputedStyle` 不为 anchor 标记返回 "inline"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22099777/