Home>
What you ca n’t do or do n’t understand

Cannot be changed by the onclick event of the source HTML button tag below.

Although I checked the uppercase and lowercase letters in detail, I did not work well with win10 IE11.

Are there any misunderstandings or mistakes?

<html>
<head>
<meta http-equiv = "content-type" content = "text/html;charset = Shift_JIS">
<script type = "text/javascript">
function change () {
handle = GetElementByID ("change");
if (handle.innerText == "Good evening") {... If the value of "handle.innerText" is "Good evening", process the next line
handle.innerText = "Hello";
handle = GetElementByID ("change_button");
handle.innerText = "change";
}… The processing when the value of "handle.innerText" is "Good evening" is over
else {... If the "if" statement is false, process the next line
handle.innerText = "Good evening";
handle = GetElementByID ("change_button");
handle.innerText = "Undo";
}… The processing when "if" is false is over
}
</script>
<title>Let ’s change errands</title>
</head>
<body>
<p>
Hello
</p>
<button onclick = "change ();">
change
</button>
</body>
</html>


Where do you point out the mistakes?

  • Answer # 1

    There is a great deal.

    function change () {
      var change = document.getElementById ("change");
      var button = document.getElementById ("change_button");
      if (change.innerText == "Good evening") {
        change.innerText = "Hello";
        button.innerText = "Change";
      } else {
        change.innerText = "Good evening";
        button.innerText = "Undo";
      }
    }


    In the first place, JS is case sensitive and should not be changed. In addition, please write according to the format because the way to write comments is also decided.

  • Answer # 2

    
    
    
    
    Let ’s change errands
    
    
        

    Hello