JavaScript事件-this传递

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用this传递当前对象本身</title>
<meta charset="utf-8" />
</head>
<body>
<img src="usa.gif" onclick="changeImg(this)" alt=""/>
<img src="mexico.gif" onclick="changeImg(this)" alt=""/> <script>
var myImages = [
"usa.gif",
"canada.gif",
"jamaica.gif",
"mexico.gif"
]; function changeImg(that) {
var newImgNumber = Math.round(Math.random() * 3); //确保随机生成的图片索引不和当前的一样
while (that.src.indexOf(myImages[newImgNumber]) != -1) {
newImgNumber = Math.round(Math.random() * 3);
} that.src = myImages[newImgNumber];
}
</script>
</body>
</html>

  

上一篇:记一次MySQl 安装1067错误


下一篇:把centos 网卡接口eth2改成eth0