zoukankan      html  css  js  c++  java
  • js 切换图片

    <html><head lang="en">
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
    <img src="img/img_01.jpg">
    <p></p>
    <button onclick="switchImg();">切换图片</button>
    <script>
       // 拿到图片标签
      var img = window.document.getElementsByTagName('img')[0];
      console.log(img.src.lastIndexOf('img_01.jpg'));
    //   lastIndexOf 如果找到则返回一个任意正数,如果没有找到,则返回-1
    //   indexOf
      function switchImg(){
          if(img.src.indexOf('img_01.jpg') != -1){
              img.src = 'img/img_02.jpg';
          }else{
              img.src = 'img/img_01.jpg';
          }
      }
    
    </script>
    
    </body></html>
  • 相关阅读:
    bzoj 4660
    bzoj 4668
    二项式反演学习笔记
    bzoj 3622
    bzoj 5306
    bzoj 3625
    任意模数NTT(二)
    bzoj 4913
    bzoj 3456
    多项式问题之五——多项式exp
  • 原文地址:https://www.cnblogs.com/yintingting/p/4623991.html
Copyright © 2011-2022 走看看