我已经通过样式表为我的html
标签应用font-size:
样式。我想用javascript检索它。获取html标签的样式属性
我试过做document.getElementsByTagName("html")[0].style
,我最终检索没有值的样式。
我已经通过样式表为我的html
标签应用font-size:
样式。我想用javascript检索它。获取html标签的样式属性
我试过做document.getElementsByTagName("html")[0].style
,我最终检索没有值的样式。
的html
元件可以通过document.documentElement
被称为尝试以下操作:
var elem = window.getComputedStyle(document.documentElement);
var fontSize = elem.fontSize;
console.log(fontSize);
html{
font-size: 20px;
}
<html>
<head>
</head>
<body>
</body>
</html>
这工作,谢谢! – Sequential
不客气。 – Mamun
请尝试以下方法:
let elem = document.getElementsByTagName("html")[0];
console.log(window.getComputedStyle(elem, null).getPropertyValue("font-size"));
的是['window.getComputedStyle()'方法](https://developer.mozilla.org/en/docs/Web/API/Window/getComputedStyle)你在找什么? – nnnnnn
@nnnnnn我尝试过应用它,但不成功 – Sequential
@nnnnnn只是试了一遍,它的工作......谢谢。 'let elem = document.getElementsByTagName(“html”)[0] \t \t \t console.log(window.getComputedStyle(elem,null).getPropertyValue(“font-size”))' – Sequential