我一直在IE中遇到这个问题。我有两个 div,用于将选定的元素从一个拖动到另一个。假设我在 div1 中有一个子元素(也是一个 div),在 div2 中有一些子元素。我在 div1 的子元素上调用 div2.appendChild() 方法。它从 div1 中删除子元素并将其附加到 div2。如果我然后尝试将孩子附加回 div1,我会在 IE 中收到以下异常“意外调用方法或属性访问”。它在 Firefox 中运行良好。请参阅下面的 javascript 代码片段。
function moveSelectedGroupBoxItems(toLocation, grp){
document.body.className = 'groupBoxDefaultCursor';
if(groupBoxfromLocation != toLocation){
if(grp == groupBoxGroup){
var fromVal = document.getElementById(groupBoxfromLocation);
var toVal = document.getElementById(toLocation);
var children = fromVal.childNodes;
for (var i = children.length - 1; i >= 0; i--) {
if(children[i].className == 'groupBoxItemSelected'){
children[i].childNodes[0].name=toLocation;
toVal.appendChild(children[i]);
}
}
}
}
groupBoxfromLocation = '';
groupBoxGroup = '';
return false;
}
这基本上在拖动时将选定的子 div 从一个父 div 移动到另一个父 div。