各位大神,下面的JS代码为什么没有出现提示报错的信息,反而是一片空白呢。原谅我是个小白!!!

<!DOCTYPE html>
<html>
<head>
<title> This is a test file</title>
</head>

<body>
<script>
function factorial(x)
{
if(x<10) throw new Error("x must not biger than 10");
for (var f=1; x<10; f*=x , x++)
return f;
}

factorial(2);

</script>
</body>

</html>

第1个回答  2016-08-22

报错原因是,你的代码要求的 throw new Error

 

可以用  alert。

function factorial(x)//求阶乘
{
 if (x==0)
 {
  return 1;
 }
 var tt=0;
 tt = factorial(x-1)*x;
 return tt;
}
alert(factorial(9));

第2个回答  2016-08-22
抛出的错误在页面是不会显示的,你用控制台比如firebug就可以看到。如果你想看到什么表现的话,建议使用alert(),会弹出一个信息框。追问

对了。我使用F12在Google Chrome里面看到报错信息了。这个为什么不显示出来啊?一般我们在网页上点点点,报错的话会自己弹出报错窗口的。我还以为这个throw的句法会实现这种功能呢。

本回答被提问者采纳