JavaScript IE appendChild() - 对方法或属性访问的意外调用 [英] JavaScript IE appendChild() - Unexpected call to method or property access

查看:103
本文介绍了JavaScript IE appendChild() - 对方法或属性访问的意外调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IE中遇到过这个问题。我有两个div用于将所选元素从一个拖到另一个。假设我在div1中有一个子元素(也是div),在div2中有一些子元素。我在div1的子元素上调用div2.appendChild()方法。它从div1中删除子项并将其附加到div2。如果我然后尝试将子项追加到div1,我在IE中得到以下异常对方法或属性访问的意外调用。它在firefox中运行得很好。请参阅下面的javascript代码片段。

I have been having this problem in IE. I have two divs which I use to drag selected elements from one to another. Lets say I have a child element (also a div) in div1 and some child elements in div2. I call the div2.appendChild() method on child element of div1. It removes the child from div1 and appends it to div2. If I then try to append the child back to div1 I get the following exception "Unexpected call to method or property access" in IE. It is working perfectly in firefox. See below code snippet for the 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。

This basically moves the selected child divs from one parent div to another on dragging.

推荐答案

已解决!...有点
我在子div中隐藏了输入,存储了id的id要移动表单提交的项目。我删除了隐藏的输入并将它们放在我的选择框下面。每次移动div时,它都会将隐藏的名称更新为父divs id。当节点有子节点时,似乎IE有appendChild()的问题。这确实有效,有时失败。添加没有子元素的单个元素始终有效。我不确定问题究竟是什么,但上面已将其整理出来。

SOLVED!... sort of I had hidden inputs within the child divs which stored the id of the item being moved for form submission. I removed the hidden inputs and placed them underneath my selectionboxes. Each time an div is moved it updates the name of the hidden to the parent divs id. It seems IE has a problem with appendChild() when the node has children. This did sometimes work and sometimes it failed. Appending a single element with no children always works. I am not sure exactly what the problem was, but the above sorted it out.

干杯

Grep

这篇关于JavaScript IE appendChild() - 对方法或属性访问的意外调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆