大家帮忙看看一个小程序啊!!

langhun1984 2006-03-07 07:51:25
function testeval()

{
window.onerror="errhandle()";
var teststr=prompt("请输入一个有效的表达式或JavaScript语句,eval可以执行输入的语句或表达式",23);
try
{
document.write("结果是:"+eval(teststr));
}
catch (err)
{ alert("输入的表达式或语句有错误!"+err);
}
}
////////////////
window.onerror="errhandle()";这句是什么意思呢?在程序中起什么作用呢?
...全文
78 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ice_berg16 2006-03-09
  • 打赏
  • 举报
回复
贴错了。
--------------------------------

那当程序有错误产生时,window.onerror="errhandle()"中的errhandle()函数是怎么执行的呢?
或者说它执行的结果是什么啊?
---------------------------------
一般来说可以在调试的时候提示一些信息,或者其它一些的处理
ice_berg16 2006-03-09
  • 打赏
  • 举报
回复
<body>
<img name="img1" src="http://community.csdn.net/images/csdn.gif" style="position:absolute;filter:alpha(opacity=0);">
</body>
<script language=javascript>
function fade(o){
this.obj = o;
this.offset=5;
this.timer = null;
this.act = "in";
this.action= function(){
//alert(this.obj.tagName);
var curOpacity = this.obj.filters.alpha.opacity;
if( this.act == "out" )
{
if(curOpacity > 0)
{
this.obj.filters.alpha.opacity-=this.offset;
}
else
{
this.act = "in";
this.obj.style.left= Math.random()*800 + "px";
this.obj.style.top = Math.random()*600 + "px";
}
}
else
{
if(curOpacity<100)
{
this.obj.filters.alpha.opacity+=this.offset;
}
else
{
this.act = "out";
}
}
};
this.play = function(){
var self=this;
var f = function(){self.action()};
this.timer=setInterval(f,40);
};
this.stop = function(){
if(this.timer) clearInterval( this.timer );
};
}
var m1 = document.images[0];
var f1 = new fade(m1);
f1.play();
</script>
langhun1984 2006-03-09
  • 打赏
  • 举报
回复
那当程序有错误产生时,window.onerror="errhandle()"中的errhandle()函数是怎么执行的呢?
或者说它执行的结果是什么啊?
zslzx 2006-03-07
  • 打赏
  • 举报
回复
因为它是当程序出错时才激发这个函数,如果不出错,当然就能正常运行,只是出错时没处理罢了
langhun1984 2006-03-07
  • 打赏
  • 举报
回复
但是我把window.onerror="errhandle()";这一句注释掉,程序也能运行通过啊~`
那这句不是多余了吗?
kangqin 2006-03-07
  • 打赏
  • 举报
回复
错误控制,当执行出现错误时进行处理。
梅雪香 2006-03-07
  • 打赏
  • 举报
回复
设置当程序出现错误的时候要执行的函数

87,910

社区成员

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

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