nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
图片对象 <script> <BR><!-- <BR>//书上说这样可以预缓存图片对象,实际是骗人的了。下面是我 特意整的特别大的图片 <BR> img1=new Image(300,400) <BR> img1.src="http://www.azsz.com/test/view/1.jpg" <BR> img2=new Image(300,400) <BR> img2.src="http://www.azsz.com/test/view/2.jpg" <BR> img3=new Image(300,400) <BR> img3.src="http://www.azsz.com/test/view/3.jpg" <BR> img4=new Image(300,400) <BR> img4.src="http://www.azsz.com/test/view/4.jpg" <BR>function img(s){//根据下拉菜单传来的值,也就是被选中项调用函数 <BR> im=document.getElementById("select1").options[s].value;//得到被选中项的值 <BR> document.getElementById("img").src=eval(im+".src")//使用eval()函数引用对象的src值并赋给页面上的图片 <BR>} <BR>//下面是DW自动生成的,所以有点不好看,懒得看了,麻烦啊,下面有我自己参考书上写的 <BR>function MM_preloadImages() { //v3.0 <BR> var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); <BR> var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) <BR> if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} <BR>} <br><br>function MM_findObj(n, d) { //v4.01 <BR> var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { <BR> d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} <BR> if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; <BR> for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); <BR> if(!x && d.getElementById) x=d.getElementById(n); return x; <BR>} <br><br>function MM_nbGroup(event, grpName) { //v6.0 <BR> var i,img,nbArr,args=MM_nbGroup.arguments; <BR> if (event == "init" && args.length > 2) { <BR> if ((img = MM_findObj(args[2])) != null && !img.MM_init) { <BR> img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src; <BR> if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array(); <BR> nbArr[nbArr.length] = img; <BR> for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) { <BR> if (!img.MM_up) img.MM_up = img.src; <BR> img.src = img.MM_dn = args[i+1]; <BR> nbArr[nbArr.length] = img; <BR> } } <BR> } else if (event == "over") { <BR> document.MM_nbOver = nbArr = new Array(); <BR> for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) { <BR> if (!img.MM_up) img.MM_up = img.src; <BR> img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up); <BR> nbArr[nbArr.length] = img; <BR> } <BR> } else if (event == "out" ) { <BR> for (i=0; i < document.MM_nbOver.length; i++) { <BR> img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; } <BR> } else if (event == "down") { <BR> nbArr = document[grpName]; <BR> if (nbArr) <BR> for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; } <BR> document[grpName] = nbArr = new Array(); <BR> for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) { <BR> if (!img.MM_up) img.MM_up = img.src; <BR> img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up; <BR> nbArr[nbArr.length] = img; <BR> } } <BR>} <BR>//--> <BR></script>
演示一:无刷新变换图片(有点歪)
1 2 3 4
演示二:鼠标触发图片变换(书面名称好像叫图像滚动)
<script> <BR> //先建立两个数组,一组是on 状态的,一组是off状态的 <BR> //数组使用的是字符串作索引,一来方便识别,二来在代码运行中不会冲突 <BR> offimg=new Array() <BR> offimg["play"]=new Image(60,50) <BR> offimg["stop"]=new Image(60,50) <BR> offimg["pause"]=new Image(60,50) <BR> offimg["rewind"]=new Image(66,55) <BR> //赋值 <BR> offimg["play"].src="img/1.jpg" <BR> offimg["stop"].src="img/2.jpg" <BR> offimg["pause"].src="img/3.jpg" <BR> offimg["rewind"].src="img/4.jpg" <BR> //第二个数组 <BR> onimg=new Array() <BR> onimg["play"]=new Image(60,50) <BR> onimg["stop"]=new Image(60,50) <BR> onimg["pause"]=new Image(60,50) <BR> onimg["rewind"]=new Image(66,55) <BR> //赋值 <BR> onimg["play"].src="img/5.jpg" <BR> onimg["stop"].src="img/6.jpg" <BR> onimg["pause"].src="img/7.jpg" <BR> onimg["rewind"].src="img/1.jpg" <BR> function on(imgname){ <BR> if(document.images){//判断浏览器是否能够处理图片对象 <BR> document.images[imgname].src=onimg[imgname].src//将对应的图片对象的src值赋给图片 <BR> } <BR> } <BR> function off(imgname){ <BR> if(document.images){//判断浏览器是否能够处理图片对象 <BR> document.images[imgname].src=offimg[imgname].src//将对应的图片对象的src值赋给图片 <BR> } <BR> } <BR> function setmsg(msg){//改变状态栏提示 <BR> window.status=msg; <BR> return true; <BR> } <BR></script>