1. 程式人生 > >js 滑鼠移動和離開

js 滑鼠移動和離開

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<script>
		 window.onload = function(){
		 	//事件源.事件=function(){}
			var pic = document.getElementById("pic");
			//滑鼠移動到圖片上
			pic.onmouseover = function(){
				pic.src = "img/1.jpg";
			}
			//滑鼠離開圖片
			pic.onmouseout = function(){
				pic.src = "img/2.png";
			}
		 }
		</script>
	</head>
	<body>
		<img src="img/2.png" id="pic" />
	</body>
</html>