Javascript img onclick没有任何影响?

Koy*_*Cho 0 html javascript html5 web

所以我有一些代码,每次up点击箭头时,它应该在一个空段落中增加1 .我正在使用Javascript,但onclick事件处理程序似乎不起作用:

<head>

  <script>
    var incremented = 0;

    function myfunction() {
      document.getElementById("uparrow").innerHTML = incremented + 1;
    }
  </script>

</head>

<body>
  <img id="uparrow" src="uparrow.png" alt="Up" onclick="myfunction()">
  <p id="incremented></p>
    </body>
Run Code Online (Sandbox Code Playgroud)

Sur*_*yan 5

你错过了打字的东西.您需要在incremented元素中插入新值,而不是插入元素uparrow.并且每次都增加你的价值.

img{
  height: 50px;
  width: 50px;
}
Run Code Online (Sandbox Code Playgroud)
<head>

<script> 
    var value = 0;

    function myIncrementfunction(){
       document.getElementById("incremented").innerHTML = ++value;
    }
    
    function myDecrementfunction(){
      document.getElementById("incremented").innerHTML = --value;
    }
    
</script>

</head>

<body>
<img id="uparrow" src="https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-arrow-up-c-128.png" alt="Up" onclick="myIncrementfunction()">
<img id="downarrow" src="http://iconizer.net/files/DefaultIcon_ver_0.11/orig/arrow-alt-down.png" alt="Up" onclick="myDecrementfunction()">
<p id="incremented">0</p>
</body>
Run Code Online (Sandbox Code Playgroud)