这个代码不是抛出错误的吗》 怎么没反正的按了

布鲁克 2011-10-23 12:21:34
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
function a()
{
var r=document.getElementById("cs").value;
if(r>10)
{
throw new Error("不能大鱼10");
}
else{
alert("d");
}
}
</script>
</head>

<body>
<input type="text" id="cs" />
<input type="button" value="按下" onclick="a()" />
</body>
</html>
...全文
46 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Legend1988 2011-10-23
  • 打赏
  • 举报
回复
楼主是什么问题呢?
代码是没问题的,大于10就抛出错误,这里如果要弹出警告对话框的话就用alert,throw只抛出错误。也可以在后面用catch捕获错误然后进行相应的操作。

87,990

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧