总的来说,就是设置个标记,或者变量来记录哪个已经被点击过了,就好了
<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>无标题 1</title>
</head><body>
<img src="http://profile.csdn.net/CocoPig/picture/2.jpg" name="info" alt="test"/>
<img src="http://profile.csdn.net/CocoPig/picture/2.jpg" name="info" alt="test"/>
<img src="http://profile.csdn.net/CocoPig/picture/2.jpg" name="info" alt="test"/>
<img src="http://profile.csdn.net/CocoPig/picture/2.jpg" name="info" alt="test"/>
<script type="text/javascript">
var imgs = document.getElementsByName("info");
var sel = null;
for(var i=0;i<imgs.length;i++)
{
imgs[i].onmouseover = function()
{
this.src = "http://profile.csdn.net/varlj/picture/2.jpg";
}
imgs[i].onmouseout = function()
{
if(sel!=this)
this.src = "http://profile.csdn.net/CocoPig/picture/2.jpg";
}
imgs[i].onclick= function()
{
if(sel==this)
return;
if(sel!=null)
{
sel.src = "http://profile.csdn.net/CocoPig/picture/2.jpg";
}
this.src = "http://profile.csdn.net/varlj/picture/2.jpg";
sel = this;
}}
</script>
</body></html>
<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>无标题 1</title>
</head><body>
<img src="http://profile.csdn.net/CocoPig/picture/2.jpg" name="info" alt="test"/>
<img src="http://profile.csdn.net/CocoPig/picture/2.jpg" name="info" alt="test"/>
<img src="http://profile.csdn.net/CocoPig/picture/2.jpg" name="info" alt="test"/>
<img src="http://profile.csdn.net/CocoPig/picture/2.jpg" name="info" alt="test"/>
<script type="text/javascript">
var imgs = document.getElementsByName("info");
var sel = null;
for(var i=0;i<imgs.length;i++)
{
imgs[i].onmouseover = function()
{
this.src = "http://profile.csdn.net/varlj/picture/2.jpg";
}
imgs[i].onmouseout = function()
{
if(sel!=this)
this.src = "http://profile.csdn.net/CocoPig/picture/2.jpg";
}
imgs[i].onclick= function()
{
if(sel==this)
return;
if(sel!=null)
{
sel.src = "http://profile.csdn.net/CocoPig/picture/2.jpg";
}
this.src = "http://profile.csdn.net/varlj/picture/2.jpg";
sel = this;
}}
</script>
</body></html>
var key=0在onclick事件后,将key=1,
并且在onmouseover 和onMouseOut事件处理函数中,都先判断一下key的值,如果key=1时表明已经被点击过,这时就不应该再变换图片了