跨度颜色不应该是绿色,它在 Chrome 中是红色的。
HTML 规范说它应该是绿色的,它在 Firefox 中是绿色的。
HTML 规范使用 fetch 来获取元素引用的资源(参见this并且 fetch 始终是异步操作。因此在新样式表加载之前获取计算的样式,因此颜色应该为绿色。
var div = document.createElement("div");
document.body.appendChild(div);
var link = document.createElement("link");
link.href = "data:text/css,div { color: red }";
link.rel = "stylesheet";
var div = document.createElement("div");
document.body.appendChild(div);
var link = document.createElement("link");
link.href = "data:text/css,div { color: red }";
link.rel = "stylesheet";
document.head.appendChild(link);
document.querySelector("span").style.color = getComputedStyle(div).color;
link.remove();
div.remove();
div { color: green }
<span>This should be green</span>