jQuery获取xml所有子节点名称
var xml = '<?xml version="1.0" encoding="utf-8" ?><BIRD><Result><name>American Wigeon</name><latin>Anas americana</latin><rare>1</rare><id>68</id><breed>0</breed><winter>0</winter></Result><Result><name>American Robin</name><latin>Turdus migratorius</latin><rare>1</rare><id>255</id><breed>0</breed><winter>0</winter></Result></BIRD>'; var $xml = $($.parseXML(xml)); $xml.find('Result').each(function() { var data={} $(this).children().each(function() { data[this.tagName]=$(this).text(); }) $('#test').data( data.id , data).append('<option value="'+data.id+'">'+data.name+'</option>'); }); $('#test').change(function(){ var data=$(this).data( $(this).val()); alert('ID:'+data.id +', Name:'+ data.name); })
相关推荐
与卿画眉共浮生 2020-10-14
xiyang 2020-08-21
baijinswpu 2020-07-29
leonranri 2020-07-26
zhongliwen 2020-07-05
麋鹿麋鹿迷了路 2020-07-05
zengyu00 2020-07-05
XGQ 2020-07-04
CoderBoy 2020-06-28
whbing 2020-06-28
绝望的乐园 2020-06-27
wellfly 2020-06-26
菇星獨行 2020-06-25
草原孤狼 2020-06-25
坚持着执着 2020-06-16
wcqwcq 2020-06-14
yuanye0 2020-06-14
zhongliwen 2020-06-13
MrFuWen 2020-06-09