js错误try...catch...
<p>Please input a number between 5 and 10:</p>
<input id="demo2" type="text">
<button type="button" onclick="myFunction()">Test Input</button>
<p id="mess"></p>
<script type="text/javascript">
function myFunction(){
var x = document.getElementById("demo2").value;
var y = document.getElementById("mess");
try{
if(x=="") throw "empty";
if(x>10) throw "too high";
if(x<5) throw "too low";
if(5 <= x <= 10) throw "is just";
if(isNaN(x)) throw "not a number";
}catch(err){
y.innerHTML = "Error:"+err+".";
}
}
浙公网安备 33010602011771号