可使用getBoundingClientRect()函式,例如html文件中標籤
some text 一些示例文字
js程式碼如下
var p = document。documentElement。querySelector(‘#demo’);
var rect = p。getBoundingClientRect();
var width = rect。right - rect。left;
var height = rect。bottom - rect。top;
alert(“width=” + width + “ height=” + height);