除非我完全注释掉try / catch代码,否则我的函数中的代码都不会运行。这是为什么?我会在try / catch之前和之后以及在try或catch中添加代码,并且什么都不会运行。
<html>
<head>
<script type="text/javascript">
var y=3;
function message()
{
try
{
alert("fdgg");
}
catch(err)
{
txt="Something went wrong, deal with it!"\n\n";
txt+="Error crap " + err.message + "\n\n";
txt+="Click Ok to do stuff.";
alert(txt);
}
alert("67");
}
</script>
</head>
<body>
<input type="button" value="Pooper" onclick="message()");
</body>
</html>
答案 0 :(得分:3)
更改
txt="Something went wrong, deal with it!"\n\n";
到
txt="Something went wrong, deal with it!\n\n";