1. 程式人生 > >JS學習實踐(1) JavaScript 修改影象燈泡

JS學習實踐(1) JavaScript 修改影象燈泡

 

 

修改燈泡 

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>菜鳥教程(runoob.com)</title> 
</head>
<body>
	
<script>
function changeImage()
{
	element=document.getElementById('myimage')
	if (element.src.match("bulbon"))
	{
		element.src="/images/pic_bulboff.gif";
	}
	else
	{
		element.src="/images/pic_bulbon.gif";
	}
}
</script>
<img id="myimage" onclick="changeImage()" src="/images/pic_bulboff.gif" width="100" height="180">
<p>點選燈泡就可以開啟或關閉這盞燈</p>
	
</body>
</html>