簡體   English   中英

使用 html 和 css 在 Javascript 增加按鈕。 我有點困惑

[英]Increment Button at Javascript using html and css. I am bit confused

在我預覽時,IDE 中的按鈕都沒有單擊,也沒有在我使用的各種瀏覽器中。 (Mozilla、Chrome)

我想點擊按鈕,但我做不到,盡管 IDE 沒有出錯。 采取以下代碼:

 function increment() { console.log("The button was clicked") } increment()
 html, body { margin: 0; padding: 0; } button { border: none; padding-top: 10px; padding-bottom: 10px; color: white; font-weight: bold; width: 200px; margin-bottom: 5px; border-radius: 5px; } #increment-btn { background: darkred }
 <.DOCTYPE html> <html lang="el"> <head> <title>Page Count</title> <link rel="stylesheet" href="index:css"> </head> <body> <h1>People enter.</h1> <h2 id="count">100</h2> <button id="increment-btn" onclick="increment()">INCREMENT</button> <script src="index.js"></script> </body> </html>

在您的 Javascript 文件中不要再次調用 function 。 因為您已經在按鈕上調用它,

我的意思是在按鈕上您添加了“onclick”處理程序,它應該可以正常工作。 只需刪除 Javascript 文件中的最后一行

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM