<html>
<head>
<title>js Error occurred</title>
<meta content="text/html;charset=UTF-8"/>
</head>
<body>
<script>
function myFunction() {
try {
var x=document.getElementById("demo").value;
if(x=="") throw "empty";
if(isNaN(x)) throw "not a number";
if(x>10) throw "too high";
if(x<5) throw "too low";
} catch(err) {
var y=document.getElementById("mess");
y.innerHTML="Error: " + err + ".";
}
}
</script>
<input id="demo" type="text">
<button type="button" οnclick="myFunction()">Test Input</button>
<p id="mess"></p>
</body>
</html>
JavaScript 错误消息
最新推荐文章于 2020-07-27 13:00:08 发布