据我了解getComputedStyles()方法,它应该返回一个对象,该对象允许访问 HTML 元素节点的实际 CSS 属性值。
我用一个包含跨度的段落创建了这个简单的示例:
let span = document.getElementsByTagName("span")[0];
let style = window.getComputedStyle(span);
span.innerText = "span background-color is " + style.getPropertyValue("background-color");
<p style="background-color: orange">
<span style="color: green">Empty</span>
</p>
段落的背景颜色是orange
,所以 span 也应该有那个属性值,还是我弄错了?会不会是继承的值被忽略了getComputedStyles
?如果是这样,我怎样才能获得跨度的实际可见背景颜色?谢谢你。