在IE8中设置innerHTML和get childNodes是不正确的

时间:2017-06-12 12:18:05

标签: javascript internet-explorer-8 innerhtml child-nodes

这是我的代码,我想得到childNodes并循环创建这些标签,但在IE8中打印2

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <div id="div"></div>
    <script type="text/javascript">
        var div = document.getElementById('div');
        var code = '<script>alert("hello");<\/script><div>dsd<\/div><script>alert("hi");<\/script>';
        div.innerHTML = code;
        console.log(div.children.length);
        console.log(div.childNodes.length)
    </script>
</body>
</html>

0 个答案:

没有答案