要準確獲取元素的clientWidth,可以通過以下方法:
var element = document.getElementById('myElement');
var width = element.clientWidth;
console.log(width);
var element = document.getElementById('myElement');
var style = window.getComputedStyle(element);
var width = parseInt(style.getPropertyValue('width'), 10);
console.log(width);
var element = document.getElementById('myElement');
var width = element.offsetWidth;
console.log(width);