1

在 Chrome 和 IE(不兼容)中,自定义标签在检查和导航 DOM 时可以正常工作。

在IE+兼容模式下,它不起作用。

这是 jsbin 中的一些示例代码:http: //jsbin.com/ozajeh/1/edit

<html>
  <!--  Run this in IE 8/9, possibly 10, with compatibility mode on to see the issue -->
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script>
        if (document.createElement) {
            document.createElement("myelement");
        }
    </script>
</head>
<body>
    <script>
        var div = $("<div>content</div>");
        if( div.contents().length > 0 && div[0].childNodes.length > 0){
            alert("found content in div");
        }

        var myElement = $("<myelement>content</myelement>");
        if (myElement.contents().length > 0 && myElement[0].childNodes.length > 0) {
            alert("found content in myelement");
        }else{
          alert("IE issue: cannot find content in myelement");
        }
    </script>
</body>
</html>

如何让 Internet Explorer 在兼容模式下正确处理标签?

当前发生的情况是 myElement.nextSibling() 返回文本节点,这显然是不正确的。

我可以根据属性/值测试找出解决方法,但是有没有更可靠的方法来处理这种情况?

4

0 回答 0