建站学 - 轻松建站从此开始!

建站学-个人建站指南,网页制作,网站设计,网站制作教程

Javascript笔记:错误处理

时间:2009-07-30 13:33来源: 作者: 点击:
Javascript笔记:错误处理

javascript代码

<html>  
<head>  
  <title>javascript</title>  
    <script type="text/javascript">  
        function test(inVal){  
            try{  
                inVal=inVal.toUpperCase();  
            }catch(error){  
                alert("An exception has occurred.Error was:\n\n"+error.message);  
            }  
        }  
    </script>  
</head>  
<body>  
<input type="button" value="Test" onclick="test(null);">  
</body>  
</html> 

<html>
<head>
  <title>javascript</title>
    <script type="text/javascript">
        function test(inVal){
            try{
                inVal=inVal.toUpperCase();
            }catch(error){
                alert("An exception has occurred.Error was:\n\n"+error.message);
            }
        }
    </script>
</head>
<body>
<input type="button" value="Test" onclick="test(null);">
</body>
</html>

利用firefox的firebug来调bug

引用

<html>
<head>
  <title>javascript</title>
    <script type="text/javascript">
        function test(){
            var a=0;
            console.log("checkpoint 1");
            a=a+1;
            console.log("checkpoint 2");
            a=a-1;
            console.log("checkpoint 3");
            a=a.toLowerCase();
            console.log("checkpoint 4");
        }
    </script>
</head>
<body>
<input type="button" value="Test" onclick="test(null);">
</body>
</html>

在IE中可以添加一个方法

引用

        function Console(){
            this.log=function(inText){
                alert(inText);
            }
        }
       var console=new Console();

(责任编辑:admin)
织梦二维码生成器
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片