在 getComputedStyle() 上获得意外结果

Getting an unexpected result on getComputedStyle()

提问人:Jeff 提问时间:10/26/2022 最后编辑:Jeff 更新时间:10/26/2022 访问量:37

问:

知道为什么并返回“Times New Roman”吗?我的代码在浏览器中运行。bodyFontFamilytest

let bodyTag = document.querySelector("body");
let bodyTagStyles = window.getComputedStyle(bodyTag);
let bodyFontFamily = bodyTagStyles.fontFamily; // returns "Times New Roman"
let test = bodyTagStyles.getPropertyValue("font-family"); // returns "Times New Roman"
let foo = bodyTagStyles.font; // returns '16px "Times New Roman"'

扩展节目bodyTagStylesfontFamily = "Monserrat, sans-serif"

enter image description here

页面的 URL 已 https://demo.directadmin.com:2222/login

该页面具有用于演示目的的自签名证书。

JavaScript 用户脚本

评论

0赞 katniss 10/26/2022
无法重现:jsfiddle.net/u7r9swdz
0赞 double-beep 10/29/2022
我假设这段代码是用户脚本的一部分。页面的CSS似乎是动态添加的。因此,当用户脚本运行时,字体系列尚未修改,因此是 Times New Roman。

答: 暂无答案