-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.html
More file actions
48 lines (46 loc) · 1.03 KB
/
Copy patherror.html
File metadata and controls
48 lines (46 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<script type="text/javascript">
/* try 语句测试代码块的错误。
catch 语句处理错误。
throw 语句创建自定义错误。
*/
var txt="";
function message()
{
try {
adddlert("Welcome guest!");
} catch(err) {
txt="本页有一个错误。\n\n";
txt +="错误描述:" + err.message + "\n\n";
txt +="点击确定继续。\n\n";
alert(txt);
}
}
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>
<input type="button" value="查看消息" onclick="message()" />
<p>请输出一个 5 到 10 之间的数字:</p>
<input id="demo" type="text">
<button type="button" onclick="myFunction()">测试输入</button>
<p id="mess"></p>
</body>
</html>