<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文檔</title> </head> <body> <img src="http://image.edusoa.com/down/Material/7A/7A3BD0EE-8FB7-4E6C-A944-CAB2D65048EB.jpg@640w_480h_100Q_1x.jpg" /> <div id="box"></div> <script language="javascript"> (function(){ var img=document.createElement('img');//建立一個img元素 img.src="http://image.edusoa.com/down/Material/7A/7A3BD0EE-8FB7-4E6C-A944-CAB2D65048EB.jpg@640w_480h_100Q_1x.jpg";//指定src img.style.position="absolute";//防止正常的內容變形 img.style.visibility='hidden';//藏起來 var inj=document.getElementById('box').appendChild(img);//插入到box中。固然插入到document.body也能夠 alert('寬:'+inj.offsetWidth);//而後就能夠經過 offset 取得寬和高了 alert('高:'+inj.offsetHeight); })(); </script> </body> </html>