OPPPPOP 2010-03-26 16:19
浏览 257
已采纳

javascript 对象丢失

[code="java"]
function invoice(st,ed,len){
this.spd=20;
this.ul=document.getElementById('invoiceing');
this.dv=this.ul.parentNode;
this.st=parseInt(st,10);
this.ed=parseInt(ed,10);
this.len=len;
this.doing.apply(this);
}
invoice.prototype={
show:function(){
this.ul.innerHTML='';
this.ul.previousSibling.innerHTML='入票中......';
this.dv.style.display='block';
this.dv.style.height=document.body.clientHeight;
this.dv.style.width=document.body.clientWidth;
},
stop:function(){
window.clearInterval(this.running);
this.ul.previousSibling.innerHTML='确定';
this.ul.previousSibling.firstChild.onclick=this.hide;
},
hide:function(){
this.dv.style.height='0px';
this.dv.style.width='0px';
this.dv.style.display='none';
},
rupiao:function(){
var o=this;
return function(){
var li=document.createElement('

');
li.innerHTML=o.lpad();
o.ul.appendChild(li);
if(o.st++>=o.ed)o.stop();
}
},
lpad:function(){
var snum=this.st.toString();
while(snum.length<this.len)snum='0'+snum;
return snum;
},
doing:function(){
this.show();
var fun=this.rupiao();
this.running=window.setInterval(fun,this.spd);
}
}
[/code]
[code="java"]


    [/code]
    这个函数在运行完毕时要给"确定"那个超链加上invioce.hide事件 ,但是发现此时的this已经不是invoice了 取不到变量dv
    求解

    • 写回答

    4条回答 默认 最新

    • wanghaolovezlq 2010-03-26 16:59
      关注

      这是因为你赋给dom对象的事件上,问题就在于事件不会马上触发,
      等它正确触发的时候,this已经不存在了,this只在对象的方法内有效

      本回答被题主选为最佳回答 , 对您是否有帮助呢?
      评论
    查看更多回答(3条)

    报告相同问题?

    悬赏问题

    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号