简体   繁体   中英

My onclick function is not working! What am I doing wrong?

I've been trying to write a Chess program with HTML, CSS, and Javascript. I cannot seem to be getting the onclick function for the "PLAY AS WHITE" button to be working. I've checked my syntax in the Javascript part and believe it looks fine to me. Is there anything I'm doing wrong with the code?

Here's the code:

 let info = document.getElementById("info"); function playAsWhite() { info.innerHTML = "the message I want to output"; }
 <h1 id="info">Playing as White:</h1> <h1>Best move:</h1> <p>NaN</p> <input type="text" placeholder="Your input:" id="inputId1"> <button onclick="player1Turn()">Enter</button> <input type="text" placeholder="Enemy input:" id="inputId2"> <button onclick="player2Turn()">Enter</button> <div class="functions"> <button onclick="playAsWhite()">PLAY AS WHITE</button> <button onclick="playAsBlack()">PLAY AS BLACK</button> <button onclick="reset()">RESET</button> </div>

I've defined the source file ("main.js") correctly, and the script is loaded at the end of body .

Your code is correct It should be "onclick". But Your javascript file is not being accessed correctly in 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