2013-04-18 42 views
-2

(“节”)在IE浏览器中查找(“科”)不工作 我有这个XML内容无法找到IE浏览器

var xmlContent = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?/><Section type="two_column" name="Section Name" id="attr_id_lines_9810"><Column align="Left"><Label>One</Label><Value>test</Value></Column><Column align="Right"><Label>Two</Label><Value>222</Value></Column></Section>'; 
$(xmlContent).find("Section").each(function(){console.log($(this).attr('type");}); 

在IE浏览器的代码无法正常工作。但其他浏览器显示正确的结果。 如果有人知道解决方案请更新。

+0

这是因为你对待像HTML而不是xml的XML。 –

+0

@KevinB jQuery能够解析XML以及:) – Archer

+1

@Archer是的,它是。但是他在上面做的是他将xml解析为HTML,并且因为IE <9不认为'section'是一个有效的html元素,所以不能没有填充就选择它。如果他使用$ .parseXML(),然后用$()包装THAT,他可以正常浏览它。 (尽管他目前的导航链仍然是错误的) –

回答

0

XML声明不是“自动关闭”或配对标签。删除斜线。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?/> 

应该是:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 

使用filter(),不.find()为 “节” 是不是一个子元素。 你也有一个不匹配的报价,你错过了一个结束括号(其中任何一个将驱动IE坚果)。

$(xmlContent).find("Section").each(function(){console.log($(this).attr('type");}); 

应该是:

$(xmlContent).filter("Section").each(function(){console.log($(this).attr('type'));}); 

放在一起,这就是:

var xmlContent = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Section type="two_column" name="Section Name" id="cust_attr_estimate_lines_9810"><Column align="Left"><Label>One</Label><Value>test</Value></Column><Column align="Right"><Label>Two</Label><Value>222</Value></Column></Section>'; 
$(xmlContent).filter("Section").each(function() { 
    console.log($(this).attr('type')); 
}); 

,我可以运行在IE8(和FF和Chrome)开发人员工具控制台,得到预期结果(two_column)没有任何问题。

相关问题