function addMore(id){
        var tb = document.getElementById("mytd")
        newfile = document.createElement("input")
        count = count + 1
        var name = "file" + count 
        newfile.setAttribute("id", name )
        newfile.setAttribute ("type","file")
        tb.appendChild (newfile)
        newfile.onclick = addMore(this.id)         
        }等我给这个 newfile的onclick事件 添加 addmore 方法的时候 页面产生了 无数个 newfile 提示内存不够。。怎么办那
这是怎么回事,

解决方案 »

  1.   

    你循环了哥们
    newfile.onclick = addMore;
      

  2.   

    哦。。循环了 啊 但是我的这个addmore的里面有一个参数要传进去 怎么传啊!
      

  3.   

    TRYnewfile.setAttribute("onclick","addMore(" + this.id + ")");
      

  4.   

    不行就用 newfile.setAttribute("onclick","addMore(this.id)")这个试试吧,不过兼容性不是很好,能兼容IE8和Firefox。
      

  5.   

    addMore(id)方法为什么要传id进来啊,你写的方法传进来也没什么用啊。
      

  6.   

    newfile.onclick = function(){addMore(id);};
      

  7.   

    第二中方法 是不行的
    newfile.setAttribute("onclick","addMore(" + this.id + ")"); 
    第一种方法倒是可以 但是不能传进去我的newfile的id啊!!这是个问题!
      

  8.   

    好了问题解决了 fandelei 1982 谢谢你 能吧你的QQ给我吗?
      

  9.   

    function addMore(id){
      var tb = document.getElementById("mytd")
      newfile = document.createElement("input")
      count = count + 1
      var name = "file" + count 
      newfile.setAttribute("id", name )
      newfile.setAttribute ("type","file")
      tb.appendChild (newfile)
      newfile.onclick =function(){ addMore(this.id);  }; // 匿名函数,就搞定 
      }