问答详情
源自:9-22 编程练习

为什么用a.onclick="dele(this)"不行?使用a.setAttribute("onclick", "dele(this)");可以的

                        td[2] = document.createElement("td");
                          var a = document.createElement("a");
                          a.href="javascript:;";
                          
                          
                          a.onclick = "dele(this)";
                        //a.setAttribute("onclick", "dele(this)");
                        
                        
                          a.innerHTML ="删除";
                          td[2].appendChild(a);
                          tr.appendChild(td[2]);
                          break;


提问者:qq_加菲喵_0 2016-06-27 15:48

个回答

  • Newbie1314
    2016-06-28 16:26:07

    a.onclick="dele(this) 改成 a.onclick=function dele(){/*里面所有需要调用this的地方直接用this代替*/}