<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>if...else</title>
<script type="text/JavaScript">
function re(){
var myage =document.getElementById('aa');//赵红的年龄为99
if(myage<=44)
{document.getElementById("bb").innerHTML = "青年";}
else if(myage<=59)
{document.getElementById("bb").innerHTML = "中年人";}
else if (myage<=89)
{document.getElementById("bb").innerHTML = "老年人";}
else
{document.getElementById("bb").innerHTML = "长寿老年人";}
}
</script>
</head>
<body>
<div>
<label>请输入你的年龄:</label>
<input id="aa" type="text" />
<input type="submit" onclick="re()" value="Submit" />
<p id="bb"></p>
</div>
</body>
</html>
var myage =document.getElementById('aa').value; //赵红的年龄为99
这样才能获取到文本输入框的值。