Home > Web Front-end > JS Tutorial > Change the image and use the example code of the match method

Change the image and use the example code of the match method

零下一度
Release: 2017-07-02 09:21:00
Original
1504 people have browsed it

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title> 
</head>
<body>
<script>
function changeImage()
{
element=document.getElementById(&#39;myimage&#39;)
if (element.src.match("bulboff"))//JavaScript String对象 Match()方法  ,如果匹配到bulboff字符,返回TRUE,否则返回FALSE
 {
  element.src="/images/pic_bulbon.gif";
  }
else
   {
  element.src="/images/pic_bulboff.gif";
   }
}
</script>
<img id="myimage" onclick="changeImage()"
src="/images/pic_bulboff.gif" width="100" height="180">
<p>点击灯泡就可以打开或关闭这盏灯</p>
</body>
</html>
Copy after login


The above is the detailed content of Change the image and use the example code of the match method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template