使用 jQuery 真的很容易。假设我们有一个这样的字符串。
<document>
<value type="people">
<name>
John
</name>
</value>
<value type="vehicle">
<name>
Ford
</name>
</value>
</document>
Run Code Online (Sandbox Code Playgroud)
然后
var xmlDocument = $.parseXML(str);
$(xmlDocument).find("value[type='people'] name").text()
Run Code Online (Sandbox Code Playgroud)
我们将得到字符串“John”。
| 归档时间: |
|
| 查看次数: |
12613 次 |
| 最近记录: |