JS学习实践(1) JavaScript 修改图像灯泡

时间:2021-09-01 17:27:36

修改灯泡

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>