必须要在DOM中后才可以获取到宽度
let dom = document.createElement('span');
dom.style.display = 'inline-block'
dom.textContent = '测试文字宽度';
document.body.appendChild(dom)
console.log(dom.clientWidth)
document.body.removeChild(dom)
必须要在DOM中后才可以获取到宽度
let dom = document.createElement('span');
dom.style.display = 'inline-block'
dom.textContent = '测试文字宽度';
document.body.appendChild(dom)
console.log(dom.clientWidth)
document.body.removeChild(dom)