<button type="button" onclick="myFunction()">测试输入值</button>
<!DOCTYPE html>
<html>
<body>
<script>
function myFunction()
{
try
var x=document.getElementById("demo").value;
if(x=="") throw "值为空";
if(isNaN(x)) throw "不是数字";
if(x>10) throw "太大";
if(x<5) throw "太小";
}
catch(err)
var y=document.getElementById("mess");
y.innerHTML="错误:" + err + "。";
</script>
<h1>我的第一个 JavaScript 程序</h1>