您的位置:首页 > Web前端 > JavaScript

Javascript 学习笔记 错误处理

2009-07-30 00:00 761 查看
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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: