编辑下面的代码:【加编码】
<html> <body> <p>输入你的年龄并点击按钮:</p> <input id="age" value="18"> <button onclick="myFunction()">点我</button> <p id="demo"></p> <script> function myFunction() { var age,voteable; age = document.getElementById("age").value; voteable = (age < 18) ? "Too young":"Old enough"; document.getElementById("demo").innerHTML = voteable + " to vote."; } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂