此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
楼主【jccdream】截止到2008-06-26 22:27:18的历史汇总数据(不包括此帖):
发帖数:0                  发帖分:0                  
结贴数:0                  结贴分:0                  
未结数:0                  未结分:0                  
结贴率:-------------------结分率:-------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html

解决方案 »

  1.   


    <html>
    <head>
        <title>test1 </title>
    </head>
    <body>
    <script type="text/javascript">
    function Element(){
    this.oFrag = document.createDocumentFragment();
    var domEl = document.createElement("input");
    this.oFrag.appendChild(domEl);
    var a=this;
    domEl.type="button";
    domEl.onclick=function(){a.clickHandler("aaa")};
    //如果这里是“domEl.onclick=this.clickHandler("aaa");”,页面加载时就会执行alert("aaa");
    }Element.prototype.clickHandler=function(value){
    alert(value);
    };Element.prototype.display = function(){
      return this.oFrag;
    };var b = new Element();
    document.body.appendChild(b.display());
    </script></body>
    </html> 
      

  2.   


    <html> 
    <head> 
        <title>test1 </title> 
    </head> 
    <body> 
    <script type="text/javascript"> 
    function Element(){ 
    this.oFrag = document.createDocumentFragment(); 
    var domEl = document.createElement("input"); 
    this.oFrag.appendChild(domEl); 
    domEl.type="button"; 
    //domEl.onclick=this.clickHandler; 
    domEl.onclick=this.clickHandler("aaa");//页面加载时就会执行alert("aaa"); 
    } Element.prototype.clickHandler=function(value){ 
     return function(){//闭包下
      alert(value); 
     }
    }; Element.prototype.display = function(){ 
      return this.oFrag; 
    }; var b = new Element(); 
    document.body.appendChild(b.display()); 
    </script> </body> 
    </html>