通过 jquery 获取 xml 中特定子项的子项值
我是 jquery 的新手,我想解析 xml 文件中的子子属性以获得特定的子属性,例如,我有这个城市和地区列表,
<city name="ANKARA">
<distr>BEYPAZARI</distr>
<distr>GÜDÜL</distr>
<distr>KAZAN</distr>
<distr>ÇANKAYA</distr>
</city>
<city name="İSTANBUL">
<distr>EMİNÖNÜ</distr>
<distr>ÇATALCA</distr>
<distr>BEYOĞLU</distr>
<distr>BEYKOZ</distr>
<distr>BEŞİKTAŞ</distr>
</city>
我使用此代码来获取城市列表,
$(xml).find('city').each(function(){
var city = $(this).attr("name");
$("<option>").text(city).appendTo("#cityList");
});
但我不知道如何获取例如安卡拉的地区列表, 有人可以帮助我吗 提前致谢
I'am a newbie in jquery and I want to parse subchilds in a xml file for a specific child attribute, for example, I have this cities and districts list
<city name="ANKARA">
<distr>BEYPAZARI</distr>
<distr>GÜDÜL</distr>
<distr>KAZAN</distr>
<distr>ÇANKAYA</distr>
</city>
<city name="İSTANBUL">
<distr>EMİNÖNÜ</distr>
<distr>ÇATALCA</distr>
<distr>BEYOĞLU</distr>
<distr>BEYKOZ</distr>
<distr>BEŞİKTAŞ</distr>
</city>
I use this code to get city list
$(xml).find('city').each(function(){
var city = $(this).attr("name");
$("<option>").text(city).appendTo("#cityList");
});
but I don't how to get the district list of for example Ankara,
someone could help me please
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这就是您想要的“属性等于”选择器。
That's the "attribute equals" selector you want.
尝试迭代所有城市和子区
Try this to iterate through all the city and the child districts
上面的两个答案都帮助我得到了我想要的,
非常感谢
both answers above helped me to get exactly what I want,
thanks a lot