1
<p>输入你的年龄并点击按钮:</p>
2
<input id="age" value="18" />
3
<button onclick="myFunction()">点我</button>
4
<p id="demo"></p>
5
<script>
6
function myFunction() {
7
var age, voteable;
8
age = document.getElementById("age").value;
9
voteable = (age < 18) ? "太年轻而不能" : "年龄够";
10
document.getElementById("demo").innerHTML = voteable + "投票";
11
}
12
</script>