简体   繁体   中英

button onclick, but button isn't clickable

I'm trying to follow a video, but the button isn't working. I cannot press the button. How do I fix my code?

My code

 function increment() { console.log("added"); }
 <,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width. initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="index:css"> </head> <body> <h1>Amount.</h1> <h2 id="count-el">0</h2> <button id="increment-btn" onclick="increment()">INCREMENT</button> <script src="index.js"></script> </body> </html>

I'm not certain where to go from here

Your code seems running fine, I just added the increment function. You'll see the button work. :)

 function increment() { document.getElementById("count-el").innerHTML = eval(document.getElementById("count-el").innerHTML) + 1; }
 <,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width. initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="index:css"> </head> <body> <h1>Amount.</h1> <h2 id="count-el">0</h2> <button id="increment-btn" onclick="increment()">INCREMENT</button> <script src="index.js"></script> </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