Javascripts的IE 9兼容性:ChildNode,SetAttribute

时间:2012-12-05 04:30:03

标签: ie-developer-tools

许多Javascripts函数在IE 9中不起作用。

具体来说,我们动态构建了一些HTML内容。现在,当我们尝试使用childNode元素访问HTML表的内容时,该对象未完全检索到它。

但是,当我们在IE 9兼容模式下运行时,我们能够得到它。

代码示例:

       var _object = document.getElementById(strTableId).childNodes[0]
       for (var iCount = 0; iCount < _object.childNodes.length; iCount++) {
            if (_object.childNodes[iCount]) {
                _object.childNodes[iCount].style.backgroundColor = 'white';
                _object.childNodes[iCount].style.color = 'black'
            }
        }

现在,当我们调试代码时,我们可以看到变量中存在的对象,但是样式属性和其他属性是不可访问的。因此,backgroundcolor行抛出了一个javascript异常。

请帮忙!

1 个答案:

答案 0 :(得分:-1)

IE 9不支持ChildNodes [0]。我们可以使用children [0]而不是ChildNodes [0]

Mohan.K