使用JQuery/Javascript从简单XML获取属性值 [英] Get Attribute Value From Simple XML Using JQuery / Javascript
本文介绍了使用JQuery/Javascript从简单XML获取属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使用我的JavaScript从以下简单的xml中获取属性值.
I tring to get the attribute value from the following simple xml using my javascript.
XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ParentNode Symbol="$"><Row book = "test" price ="80"/></ParentNode>
jQuery:$('ParentNode').attr('Symbol');
如果xml代码为
<ParentNode Symbol="$"><Row book = "test" price ="80"/> </ParentNode>
推荐答案
尝试
var string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ParentNode Symbol="$"><Row book = "test" price ="80"/></ParentNode>';
var $doc = $.parseXML(string);
console.log($($doc).find('ParentNode').attr('Symbol'))
演示:小提琴
这篇关于使用JQuery/Javascript从简单XML获取属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文