标签:
<!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>
标签:
原文地址:http://www.cnblogs.com/cczhoufeng/p/4291525.html