我正在尝试获取 XML 节点的子节点的长度。除 chrome 外,其他浏览器似乎给出了准确的结果。假设如果孩子的数量是 6,chrome 返回 13。因此,方法hasChildNodes()
或hasChildren()
返回Uncaught TypeError: Cannot call method 'hasChildNodes' of undefined
错误。您能否建议我一些替代方案,以便我可以在 Chrome 中运行我的代码。
$.ajax({
type: "GET",
url: "tree1.xml",
dataType:"xml",
success: function(xml){
var root=xml.documentElement;
var childs1=root.childNodes;
var len=$(childs1).size();
alert(len);
这是代码的一部分,我在其中提醒孩子的数量。根元素有 6 个子元素。但 chrome 警告 13