/** 设置 rem 函数 */ function setRem() { console.log(222223) const htmlWidth = document.documentElement.clientWidth || document.body.clientWidth const htmlDom = document.getElementsByTagName('html')[0] console.log(htmlWidth, htmlDom.style.fontSize) htmlDom.style.fontSize = htmlWidth / 100 + 'px' } setRem() window.onresize = function () { setRem() }