运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Comparison</h1> <h2>The () ? : Ternary Operator</h2> <p>Input your age and click the button:</p> <input id="age" value="18" /> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { let age = document.getElementById("age").value; let voteable = (age < 18) ? "Too young":"Old enough"; document.getElementById("demo").innerHTML = voteable + " to vote."; } </script> </body> </html>