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需刷新才能执行]
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- 图片与文字半透明效果 鼠标移上不透明
- JavaScript 复制功能代码 兼容多浏览器
- 图片与JavaScript配合做出个性滚动条
- 简单的加密css地址防止别人下载你的CSS文件的方法
- 图片友情链接滚动 横向,带控制按钮
- javascript 定时自动切换的选项卡Tab
- JS 仿Flash动画放大/缩小容器
- document.onreadystatechange事件的用法分析
- 将jQuery应用于login页面的问题及解决
- 层序遍历在ExtJs的TreePanel中的应用
- JavaScript 基于原型的对象(创建、调用)
- JavaScript 定义function的三种方式小结
- JavaScript 函数式编程的原理
- 实现JavaScript中继承的三种方式
- 显示js对象所有属性和方法的函数
- 半角全角相互转换的js函数
- JavaScript 三种创建对象的方法
- JQuery困惑—包装集 DOM节点
- JavaScript 对象成员的可见性说明