for(var i=0;i<pram;i++)
{
var mybotton=document.createElement("<input name=\"submit" + i + "\">");
       mybotton.setAttribute("type","button");
   mybotton.setAttribute("value","上传大图");
   mybotton.setAttribute("id",i);
  mybotton.attachEvent("onclick", function(){ window.open("upload_flash_d.asp?formname=form1&editname=filename"+i+"&uppath=../upimage/b_images&filelx=jpg","","status=no,scrollbars=no,top=20,left=110,width=420,height=165")});
 thisTd.appendChild(mybotton);
}想问一下如何给onclick事件的匿名函数把i传进去啊?

解决方案 »

  1.   

    mybotton.attachEvent("onclick", function(v){return function(){
    alert(v);
    }}(i));
      

  2.   

    你不是已经保存了。直接使用就好了//mybotton.setAttribute("id",i);  //这句就把i的值保存到自己的属性里去了mybotton.attachEvent("onclick", function(){ alert(this.id)});
      

  3.   

    可以使用event对象的属性来获取自己的id:mybotton.attachEvent("onclick", function(){alert(event.srcElement.id); });