如下所示类:function apSecurityAdvance(objID)
{
  
  this.appendTo = document.getElementById(objID);
  this.appendTo.style.cssText="padding:3px;background-color:rgb(206,225,250);margin: 0 6px;";
  this.frm =  this.createAdvanceform();
}
apSecurityAdvance.prototype.createAdvanceform=function()
{
    var button=document.createElement("input");//创建一个按钮,用于显示隐藏权限设定
button.value="Advance";
button.type="button";
button.style.cssText="float:left;font-size:9pt;border:1px #dddddd solid;padding:3px 1px 1px 1px;height:20px;margin-top:3px;margin-left:0px;";
button.onclick=function()
{
           this.onclick();        //这样写会出错,怎么写才不会有问题?
};
}
apSecurityAdvance.prototype.onclick=function()
{
 //处理代码
}
谢谢!

解决方案 »

  1.   

    应该是apSecurityAdvance对象.onclick();你的代码中this并不是指apSecurityAdvance对象,而是button对象
      

  2.   

    this.onclick()这句代码中this并不是指apSecurityAdvance对象,而是button对象
      

  3.   

    谢谢两位:还有一个问题,这条语句处 
    button.onclick=function()我添加事件源对象:button.onclick=function(oEvent)调试时发现oEvent为undefined,咋回事,怎样才能取道事件源对象
      

  4.   


    t添加参数
    apSecurityAdvance.prototype.onclick=function(evnt)
    {
     //处理代码
    }
     button.onclick=function(event)
    {};
      

  5.   


    在FF下会有对象,但在IE下不会有,IE下直接使用(window.)event对象就行了(仅在事件处理函数下有效)
      

  6.   

     至于上一个问题,你可以在
       button.onclick=function()
    {
               this.onclick();        //这样写会出错,怎么写才不会有问题?
    };
    这段代码的上面加一句
        var _this=this;
    然后将代码改成:
        button.onclick=function()
       {
           _this.onclick();        
        };
      

  7.   


    function apSecurityAdvance(objID)
    {
      
      this.appendTo = document.getElementById(objID);
      this.appendTo.style.cssText="padding:3px;background-color:rgb(206,225,250);margin: 0 6px;";
      this.frm =  this.createAdvanceform();
    }
    apSecurityAdvance.prototype.createAdvanceform=function()
    {
        var button=document.createElement("input");//创建一个按钮,用于显示隐藏权限设定
        button.value="Advance";
        button.type="button";
        button.style.cssText="float:left;font-size:9pt;border:1px #dddddd solid;padding:3px 1px 1px 1px;height:20px;margin-top:3px;margin-left:0px;";
    var targetThis = this;
        button.onclick=function(e) {
        var event = e || window.event;
            //this.onclick();        //这样写会出错,怎么写才不会有问题?
         targetThis.onclick();
    };
    }
    apSecurityAdvance.prototype.onclick=function()
    {
     //处理代码
    }看看我的代码和你的有什么不同