未捕获的类型错误:无法读取 null javascript 的属性“parentNode”
2013-08-23
20864
此代码应使元素在被拖放到另一个元素(称为 cookiemonster)上时从列表中消失
addEvent(cookiemonster, 'drop', function (e) {
if (e.stopPropagation) e.stopPropagation();
var el = document.getElementById(e.dataTransfer.getData('text'));
el.parentNode.removeChild(el);
return false;
});
1个回答
创建一个像这样的辅助变量
addEvent(cookiemonster, 'drop', function (e) {
if (e.stopPropagation) e.stopPropagation();
var el = document.getElementById(e.dataTransfer.getData('text'));
var aux = el.parentNode;
aux.removeChild(el);
return false;
});
eventHandler
2014-03-26