<script   language="javascript">
function   myclass(sTypename,oTag){
aaa=this;
this.typename=sTypename;
this.tag=oTag;
this.tag.onclick=function (){aaa.onclick()};
}
myclass.prototype.show=function(){
this.tag.innerHTML=this.typename;
}myclass.prototype.onclick=function(){
alert(arguments.length);
alert(this.typename);
}var   oMycls=new   myclass("abc",document.getElementById("mydiv"));
oMycls.show();</script>

解决方案 »

  1.   

    用闭包,我怎么没有想到呢.确实可以访问类内的对象了,可是还有一个问题就是我怎么可以得到event对象呢,要不然就兼容不了浏览器了.
      

  2.   

    <div   id="mydiv"> ddddd </div> 
    <script   language="javascript">
    function   myclass(sTypename,oTag){
    aaa=this;
    this.typename=sTypename;
    this.tag=oTag;
    this.tag.onclick=function (event){aaa.onclick(event)};
    }
    myclass.prototype.show=function(){
    this.tag.innerHTML=this.typename;
    }myclass.prototype.onclick=function(e){
    var e=e||window.event;
    var obj = e.srcElement||e.target;
    alert(obj.tagName);
    alert(arguments.length);
    alert(this.typename);
    }var   oMycls=new   myclass("abc",document.getElementById("mydiv"));
    oMycls.show();</script>