JavaScript:改变 HTML 图像(点击灯泡就可以打开或关闭这盏灯)
作者:互联网
实现点击切换图片
<!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="http://www.runoob.com/images/pic_bulboff.gif";
}
else
{
element.src="http://www.runoob.com/images/pic_bulbon.gif";
}
//element.src="http://www.runoob.com/images/pic_bulbon.gif";
}
</script>
<img id="myimage" onclick="changeImage()" src="http://www.runoob.com/images/pic_bulboff.gif" width="100" height="180">
<p>点击灯泡就可以打开或关闭这盏灯</p>
</body>
</html>
标签:盏灯,src,www,runoob,JavaScript,element,HTML,images,com 来源: https://blog.csdn.net/update7/article/details/87904001