如何给页面所有图像添加事件使之可以动态改变大小?
我写了一个代码,但结果总是不尽人意。
我原想通过FOR循环给所有的图像都加上事件处理函数,但下面代码的结果只能使页面中的最后一个图像改变大小,可能是它bbimg()函数传递的始终都只是最后一个IMAGE对象。
请大虾们解答!解出即送分!
<img SRC="file:///C:/Inetpub/wwwroot/teer/chinese/img/specpic/01.jpg" width="600" height="806"><br><br>
<img SRC="file:///C:/Inetpub/wwwroot/teer/chinese/img/specpic/02.jpg" width="780" height="1042"><br><br>
<img SRC="file:///C:/Inetpub/wwwroot/teer/chinese/img/specpic/03.jpg" width="780" height="971">
<script language="javascript">
DoAll();
//改变图片大小,添加事件处理代码
function DoAll()
{
var i;
var img=new Image();
for(i=0;i<document.images.length;i++)
{
img=document.images[i];
if(img.width>500)
{
img.width=500;
img.attachEvent("onmousewheel",function Event_ResizeImage(){ return bbimg(this); } );
}
}
}
function bbimg(o){
var zoom=parseInt(o.style.zoom, 10)||100;zoom+=event.wheelDelta/12;if (zoom>0) o.style.zoom=zoom+'%';
return false;
}
</script>