js 获取网络图片的高度和宽度的实现方法(变通了下)

  作者:bea

<!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


<!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>
原图片是 :尺寸是(215*78)
<img src="http:///images/logo.gif" />
<div id="box"></div>
<script language="javascript">
(function(){
var img=document.createElement('img');//创建一个img元素
img.src="http:///images/logo.gif";//指定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>




[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]



有用  |  无用

猜你喜欢