x
 
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript 比较</h1>
<p>请输入您的年龄然后点击按钮:</p>
<input id="age" value="18" />
<button onclick="myFunction()">试一试</button>
<p id="demo"></p>
<script>
function myFunction() {
  var age, voteable;
  age = Number(document.getElementById("age").value);
  if (isNaN(age)) {
    voteable = "输入值不是数字";
  } else {
    voteable = (age < 18) ? "好年轻" : "够成熟";
  }
  document.getElementById("demo").innerHTML = voteable;
}
</script>
</body>
</html>