本节内容:
JS获取图片宽高的代码
例1,
 
复制代码 代码示例:
<img src="http://www.jb200.com/images/guangg/2009year.jpg" width="200" id="imgs" onload="GetF.call(this)"/>
<script language="
javascript">
function GetF(){
 var ig = new Image();
 ig.src = this.src;
 alert(ig.width + "n" + ig.height);
}
</script>
看到以上代码,想到了with的用法,加以实现:
 
复制代码 代码示例:
<img src="http://www.jb200.com/images/guangg/2009year.jpg" width="200" onload="GetF(this.src)"/>
<script>
function GetF(x){
    with(new Image){
       src = x;
       alert(width + "n" + height);
    }
}
</script>
with 语句
为语句设定默认对象。
with (object)
   statements
参数
object 
新的默认对象。
statements 
一个或多个语句,object 是该语句的默认对象。
说明
with 语句通常用来缩短特定情形下必须写的代码量