beat.src=="img/gray.png" 这一句过不去

来源:-

文翰弟

2015-04-10 17:15

<!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>


写回答 关注

1回答

  • 西地锦
    2015-04-11 15:24:43

    访问Element的属性可以用 getAttribute方法,设置Element属性可以用setAttribute方法,具体用法

    Element.getAttribute("attrName");
    Element.setAttribute("attrName","value");


CSS3实现漂亮ToolTips效果

CSS3 实现鼠标悬停弹出信息提示框,学习达到对CSS3深入了解的目的

42722 学习 · 101 问题

查看课程

相似问题