我有一个像
<?xml version="1.0" encoding="ISO-8859-1"?>
<childrens>
<child entity_id="1" value="Root Catalog" parent_id="0">
<child entity_id="2" value="Apparel" parent_id="1">
<child entity_id="4" value="Shirts" parent_id="2"/>
<child entity_id="5" value="Pants" parent_id="2"/>
</child>
<child entity_id="3" value="Accessories" parent_id="1">
<child entity_id="6" value="Handbags" parent_id="3"/>
<child entity_id="7" value="Jewelry" parent_id="3"/>
</child>
</child>
</childrens>
n 已尝试获取 parent_id=2 n 已编写此 jquery 代码的数据
$(document).ready(function(){
$.ajax({
type: "GET",
url: "test.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('child').attr('[parent_id=3]').each(function(){
var id = $(this).attr('entity_id');
alert(id);
});
}
});
});
但它不工作
如果我删除.attr('[parent_id=3]')
,那么每个 id 都会被提醒