Javascript 学习笔记 错误处理

Java代码
复制代码 代码如下:
<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();

JavaScript技术Javascript 学习笔记 错误处理,转载需保留来源!

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。