<body>
<html>
<script>
function f() {
try {
//获取用户输入的数据
var x = document.getElementById("demo").value;
if (x == "") throw "值为空";
if(isNaN(x)) throw "不是数字";
if(x>=10 ) throw "太大";
if(x<=5) throw "太小";
}
//e 接受throw 的错误信息
catch (e) {
var y=document.getElementById("ee");
y.innerHTML = "错误" + e
}
}
</script>
<p>请输入一个数字</p>
<input id = "demo" type="text">
<button type = button onclick="f()">测试输入</button>
<p id="ee"></p>
</body>
</html>