1 回答

TA贡献1856条经验 获得超5个赞
在我andrio手机上测试有效
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
</style>
</head>
<body>
<div id="div">rfgdfdgdghfgsgfg</div>
<div id="font"></div>
</body>
<script>
window.onload = function(){
const div = document.getElementById('div');
const font = document.getElementById('font');
// console.dir(div.style.fontFamily);
function getFontFamily(elem) {
var computedStyles = window.getComputedStyle(elem);
console.log(computedStyles['font-family']);
font.innerText = computedStyles['font-family'];
}
getFontFamily(div);
}
</script>
</html>
添加回答
举报