W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <p>我在想一个字母。猜猜是哪个:a、b、c、d 或 e?</p> <input id="myInput" type="text"> <button onclick="myFunction()">试一试</button> <p id="demo"></p> <script> function myFunction() { var letter = document.getElementById("myInput").value; var text; // 如果字母是 "c" if (letter === "c") { text = "Spot on! Good job!"; // 如果字母是 "b" 或 "d" } else if (letter === "b" || letter === "d") { text = "Close, but not close enough."; // 如果是其他字母 } else { text = "Waaay off.."; } document.getElementById("demo").innerHTML = text; } </script> </body> </html>