JS-异常处理

 

  自定义异常:

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4 <meta charset="UTF-8">
 5 <title>Insert title here</title>
 6      
 7 </head>
 8 <body>
 9     <form>
10        <input id="txt" type="text">
11        <input id="btn" type="button" onclick="demo()" value="按钮">
12     </form>
13     <script>
14        function demo(){
15            try{
16                var e = document.getElementById("txt").value;
17                if(e==""){
18                     throw "请输入";
19                }
20            }catch(err){
21                alert(err);
22            }
23        }
24     </script>
25     
26 </body>
27 </html>

 

posted @ 2016-08-08 19:17  UniqueColor  阅读(135)  评论(0编辑  收藏  举报