(function(){
var xmlString="<Family><people><title>News for Golf</title></people><people><title>News for NBA</title></people></Family>"
$(xmlString).find('people').each(function(){
alert($(this).html());
});
})(jQuery);
上面的代码在 FF 上运行良好并给出
<title>News for Golf</title>
<title>News for NBA</title>
但不是在 IE 中,任何人都可以建议 IE 的问题是什么,我需要与上面相同的输出。
另外,如果可能的话我到底想要的是
<people><title>News for Golf</title></people>
<people><title>News for NBA</title></people>
谢谢, 债券
最佳答案
您没有将 XML 解析为 Jquery 可以正确使用的格式。
参见:http://api.jquery.com/jQuery.parseXML/
你应该这样做:
var xmlstring = '<Family><people><title>News for Golf</title></people><people><title>News for NBA</title></people></Family>';
var xmlDoc = $.parseXML(xmlstring);
var $xml = $(xmlDoc);
var $people = $xml.find('people');
$.each($people,function(index,person){
//Here person refers to the person node of the XML
});
关于javascript - 使用 jquery 迭代 xml 在 FF 中工作正常,但在 IE 中则不行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10809377/