js获取网络图片的宽和高

<!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> 
相关文章
相关标签/搜索