码迷,mamicode.com
首页 > Web开发 > 详细

Js异常捕获

时间:2018-07-13 00:01:30      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:click   utf-8   try   script   code   onclick   nbsp   round   function   

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <script>
            function demo(){
                try{
                    alert(str);
                }catch(e){
                    alert(e);
                }
            }
            demo();
        </script>
        
        <form>
            <input id="txt" type="text"/>
            <input id="btn" type="button" onclick="demo1()" value="按钮" />
        </form>
        <script>
            function demo1(){
                try{
                    var e=document.getElementById("txt").value;
                if(e==""){
                    throw "请输入";
                }
                }catch(e){
                    alert(e);
                }
                
            }
        </script>
    </body>
</html>

 

Js异常捕获

标签:click   utf-8   try   script   code   onclick   nbsp   round   function   

原文地址:https://www.cnblogs.com/nullcodeworld/p/9302365.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!