js中try/catch/throw的用法

来源:互联网 发布:大唐软件 编辑:程序博客网 时间:2024/05/01 20:12
<html><body><script type="text/javascript">var x=prompt("Enter a number between 0 and 10:","")try{ if(x>10) throw "Err1"else if(x<0)throw "Err2"} catch(er){if(er=="Err1") alert("Error! The value is too high")if(er == "Err2") alert("Error! The value is too low") }</script></body></html>
原创粉丝点击