<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>星星之火可以燎原</title>
</head>
<body>
<img id="beat" src="img/gray.png" onclick="light()" />
</body>
<script>
function light(){
var beat=document.getElementById("beat");
if(beat.src=="img/gray.png"){
beat.src="img/yellow.png";
}else{alert(44);
beat.src="img/gray.png";
}
}
</script>
</html>访问Element的属性可以用 getAttribute方法,设置Element属性可以用setAttribute方法,具体用法
Element.getAttribute("attrName");
Element.setAttribute("attrName","value");