<body>
<p>请输入1~10的数字:</p>
<input id="input" type="text" onfocus="clearAll(this)">
<input type="button" value="校验" onclick = "check()">
<p id="msg"></p>
</body>
<script>
function check(){
try{
var x = document.getElementById("input").value;
if(x==""){throw "值为空!";}
if(isNaN(x)){throw "不是数字!";}
if(x<1){throw "数字太小!";}
if(x>10){throw "数字太大!";}
}
catch(error){
var y = document.getElementById("msg");
y.innerHTML = "错误:" + error ;
}
}
function clearAll(x){
x.value="";
}
</script>