应该可以的 ,你再调试下在 keyDown 函数里面 alert (this.showExpress) 看看是对象不?不是的话就是 调用的有问题

解决方案 »

  1.   

    谢谢你啊.alert(this.showExpress)结果为undefined.
    那原因在哪里呢!
    如果我注释掉this.showExpress就能正常执行呢!Herts.Widget.Calculators.prototype.showExpress = function(){
         alert('看来能在onkeydown事件函数里调用其它函数');
    };
      

  2.   

    这至少说明 在 keyDown 函数里面 ,你的 showExpress  是未定义的 ,
    你不能把 showExpress   方法写在 外边吗?Herts.Widget.Calculators   =   function(){ 
    this.onKeyDownBoolen   =   true; 
    document.onkeydown   =   this.keyDown; 
    }; 
    //键盘事件 
    Herts.Widget.Calculators.prototype.keyDown   =   function(){ 
    alert('这一句能正常执行'); 
    showExpress(); 
    }; 
    var showExpress   =   function(){ 
    alert('这里也能执行); 
    };
      

  3.   

    var _CalcStandard = new Herts.Widget.Calculators("popedCalc_id");
    如果将上面的this.showExpress()改成_CalcStandard.showExpress();也能执行.跟楼上的一个原理.
    showExpress不是已经加到原型里面去了吗?
      

  4.   

    嗯.谢谢各位啊!
       看了你们两位回答.我认为原因可能是
    document.onkeydown事件触发后.对象是document.
    对于onkeydown事件函数来说.this.showExpress这里函数不存在!
    现在问题怎么来把onkeydown事件重写.加到Widget中来.
      

  5.   

    原因就是因为this指针改变了。
    document.onkeydown = this.keyDown; 
    改成
    var _method = this.keyDown, obj = this;
    document.onkeydown = function(){_method.apply(obj);}