简体   繁体   中英

I don't know what's wrong when i click the button nothing work

var zer = document.getElementById("zer");

zer.addEventListener("click", function(){

document.getElementById("info").innerHTML = "Hello World";    
})

Hope you get where you were wrong.

The best practice is to keep the scripts at the end so that all the html code is loaded and then the scripts are loaded.

      <!DOCTYPE html>
      <html>
      <head>
      <link href="style.css" rel="stylesheet">
      </head>
      <body> 
        <div id="container">
          <button id="zer" >click here</button>
          <div id="info"></div>
         </div>
        <script src="script.js"></script>
        <script src="jquery-3.3.1.min.js">
      </body>
       </html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM