function creatediv(id) { var newdiv = document.createElement('div'); newdiv.setAttribute('id',id); newdiv.onclick=function(){this=null;}; //bad function document.body.appendChild(newdiv); }
我错过了什么?
谢谢
function creatediv(id) { var newdiv = document.createElement('div'); newdiv.setAttribute('id',id); newdiv.onclick=function(e) { this.parentNode.removeChild(this); }; document.body.appendChild(newdiv); newdiv = null;//required in IE to prevent memory leak }