<html><head><title>Image Gallery</title></head><body><h1>Snapshots</h1><ul><li><ahref="image/fireworks.jpg"onclick="showPic(this); return false;"title="a fireworks display">fireworks</a>//鼠标点击时,不在另一个页面显示,而是在显示区域显示。点击返回false,则不会跳转
</li><li><ahref="image/coffee.jpg"onclick="showPic(this); return false;"title="a cup of black coffee">coffee</a></li><li><ahref="image/rose.jpg"onclick="showPic(this); return false;"title="a red rose">rose</a></li><li><ahref="image/bigben.jpg"onclick="showPic(this); return false;"title="the famous clock">bigben</a></li></ul><imgid="placeholder"src="image/placeholder.gif"alt="my image gallery" /></body></html>
function showPic(whichpic)
{ var source=whichpic.getAttribute("href");//首先检索到图片的地址
var placeholder=document.getElementById("placeholder");//找到被替换图片的位置
placeholder.setAttribute("src",source);//替换 另一种方法 placeholder.src=source;
}