複製代碼 代碼如下:<%@LANGUAGE="JAVASCRIPT" CODEPAGE="936"%>
<!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=gb2312" />
<title>圖片對象</title>
<script language="javascript">
<!--
//書上說這樣可以預緩衝圖片對象,實際是騙人的了。下面是我 特意整的特別大的圖片
img1=new Image(300,400)
img1.src="http://www.azsz.com/test/view/1.jpg"
img2=new Image(300,400)
img2.src="http://www.azsz.com/test/view/2.jpg"
img3=new Image(300,400)
img3.src="http://www.azsz.com/test/view/3.jpg"
img4=new Image(300,400)
img4.src="http://www.azsz.com/test/view/4.jpg"
function img(s){//根據下拉式功能表傳來的值,也就是被選中項調用函數
im=document.getElementById("select1").options[s].value;//得到被選中項的值
document.getElementById("img").src=eval(im+".src")//使用eval()函數引用對象的src值並賦給頁面上的圖片
}
//下面是DW自動產生的,所以有點不好看,懶得看了,麻煩啊,下面有我自己參考書上寫的
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
if (event == "init" && args.length > 2) {
if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
nbArr[nbArr.length] = img;
for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
if (!img.MM_up) img.MM_up = img.src;
img.src = img.MM_dn = args[i+1];
nbArr[nbArr.length] = img;
} }
} else if (event == "over") {
document.MM_nbOver = nbArr = new Array();
for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
if (!img.MM_up) img.MM_up = img.src;
img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
nbArr[nbArr.length] = img;
}
} else if (event == "out" ) {
for (i=0; i < document.MM_nbOver.length; i++) {
img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
} else if (event == "down") {
nbArr = document[grpName];
if (nbArr)
for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
document[grpName] = nbArr = new Array();
for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
if (!img.MM_up) img.MM_up = img.src;
img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
nbArr[nbArr.length] = img;
} }
}
//-->
</script>
</head>
<body onload="MM_preloadImages('img/3.jpg','img/2.jpg','img/4.jpg')">
<p><strong>示範一:無重新整理變換圖片(有點歪)</strong></p>
<p>
<select name="select1" onchange="img(this.options.selectedIndex)">
<option value="img1">1</option>
<option value="img2">2</option>
<option value="img3">3</option>
<option value="img4">4</option>
</select>
<input type="image" name="img" src="img/7.jpg" />
</p>
<p><strong>示範二:滑鼠觸發圖片變換(書面名稱好像叫映像滾動)</strong></p>
<p>
<script language="javascript">
//先建立兩個數組,一組是on 狀態的,一組是off狀態的
//數組使用的是字串作索引,一來方便識別,二來在代碼運行中不會衝突
offimg=new Array()
offimg["play"]=new Image(60,50)
offimg["stop"]=new Image(60,50)
offimg["pause"]=new Image(60,50)
offimg["rewind"]=new Image(66,55)
//賦值
offimg["play"].src="img/1.jpg"
offimg["stop"].src="img/2.jpg"
offimg["pause"].src="img/3.jpg"
offimg["rewind"].src="img/4.jpg"
//第二個數組
onimg=new Array()
onimg["play"]=new Image(60,50)
onimg["stop"]=new Image(60,50)
onimg["pause"]=new Image(60,50)
onimg["rewind"]=new Image(66,55)
//賦值
onimg["play"].src="img/5.jpg"
onimg["stop"].src="img/6.jpg"
onimg["pause"].src="img/7.jpg"
onimg["rewind"].src="img/1.jpg"
function on(imgname){
if(document.images){//判斷瀏覽器是否能夠處理圖片對象
document.images[imgname].src=onimg[imgname].src//將對應的圖片對象的src值賦給圖片
}
}
function off(imgname){
if(document.images){//判斷瀏覽器是否能夠處理圖片對象
document.images[imgname].src=offimg[imgname].src//將對應的圖片對象的src值賦給圖片
}
}
function setmsg(msg){//改變狀態列提示
window.status=msg;
return true;
}
</script>
<table width="591" border="1">
<tr>
<td width="169"><table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><a href="http://thcjp.cnblogs.com" target="_top" onclick="MM_nbGroup('down','group1','Blogs','img/3.jpg',1)" onmouseover="MM_nbGroup('over','Blogs','img/2.jpg','img/4.jpg',1)" onmouseout="MM_nbGroup('out')"><img src="img/1.jpg" alt="田轟穿部落格" name="Blogs" width="80" height="120" border="0" id="Blogs" onload="" /></a></td>
</tr>
</table>
<p><a href="http://thcjp.cnblogs.com">上面是DW做的<br />
是預載入圖片</a></p></td>
<td width="406">
<a href="http://thcjp.cnblogs.com"><img src="img/1.jpg" width="80" height="120" border="0" name="play" onMouseOver="on('play');return setmsg('我的教程部落格 --> http://thcjp.cnblogs.com')" onmouseout="off('play');return setmsg('');" /></a>
<a href="http://www.cnblogs.com/thcjp/category/65304.html"><img src="img/2.jpg" width="80" height="120" border="0" name="stop" onmouseover="on('stop');return setmsg('天轟穿的部落格之js入門系列教程--> http://www.cnblogs.com/thcjp/category/65304.html')" onmouseout="off('stop');return setmsg('')"/></a>
<a href="http://www.cnblogs.com/thcjp/category/59325.html"><img src="img/3.jpg" width="80" height="120" border="0" name="pause" onmouseover="on('pause');return setmsg('VS2005控制項系列教程 http://www.cnblogs.com/thcjp/category/59325.html')" onmouseout="off('pause');return setmsg('')"/></a>
<a href="http://thcjp.cnblogs.com"><img src="img/4.jpg" width="80" height="120" border="0" name="rewind" onmouseover="on('rewind');return setmsg('ajax系列視頻教程 --> http://thcjp.cnblogs.com')" onmouseout="off('rewind');return setmsg('');" /></a></td>
</tr>
</table>
</body>
</html>