1. 程式人生 > >js點選按鈕更改html頁面的圖片(兩個來回換)

js點選按鈕更改html頁面的圖片(兩個來回換)

<!DOCTYPE html>
<html>
<body>

<img id="image" src="111.png" onmousedown="secound(this)" onmouseup="first(this)">
<button onclick="change()">點選換圖片</button>
<script>
    function change() {
          var x = document.getElementById("image").getAttribute("src");

          if (x=="111.png"){
              document.getElementById("image").src="222.png";
          }
          else{
              document.getElementById("image").src="111.png";
          }
          //alert(x);
    }

    function secound(obj){
        obj.src="222.png";
        console.log(obj.getAttribute("src"));
    }

    function first(obj){
        obj.src="111.png";
        console.log(obj.getAttribute("src"));
    }
</script>

</body>
</html>

這裡是我們的圖片


 頁面效果:
http://shuaishuaicloud.cn/4444.mp4 

 
(我的騰訊雲主機) 可能到2018 6 就不能用了那時我已畢業