js获取手机在默认字体

嵌入到手机内的html页面,如何获取系统默认字体,大家有用到过的吗?

慕容708150
浏览 608回答 1
1回答

RISEBY

在我andrio手机上测试有效<!DOCTYPE html><html><head>&nbsp; &nbsp; <meta charset="UTF-8">&nbsp; &nbsp; <title>Document</title>&nbsp; &nbsp; <style>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; </style></head><body>&nbsp; &nbsp; <div id="div">rfgdfdgdghfgsgfg</div>&nbsp; &nbsp; <div id="font"></div></body><script>&nbsp; &nbsp; window.onload = function(){&nbsp; &nbsp; &nbsp; &nbsp; const div = document.getElementById('div');&nbsp; &nbsp; &nbsp; &nbsp; const font = document.getElementById('font');&nbsp; &nbsp; &nbsp; &nbsp; // console.dir(div.style.fontFamily);&nbsp; &nbsp; &nbsp; &nbsp; function getFontFamily(elem) {&nbsp; &nbsp; &nbsp; &nbsp; var computedStyles = window.getComputedStyle(elem);&nbsp; &nbsp; &nbsp; &nbsp; console.log(computedStyles['font-family']);&nbsp; &nbsp; &nbsp; &nbsp; font.innerText = computedStyles['font-family'];&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; getFontFamily(div);&nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;</script></html>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript