XML代码
<sterowniki>
<items id="1" name="name" >
<opis>Lorem lipsum</opis>
<zdjecie picture="img/car.png"> </zdjecie>
</items>
</sterowniki>
jQuery问题
function parseXml(xml) {
var id_elem = $.urlParam('id');
$(xml).find("sterowniki").each(function() {
$(xml).find('items[id="' + id_elem + '"]').each(function() {
$("#nazwa").append('<h3 align="center"class="col-xs-7 col-sm-6 col-md-6 col-lg-8"><b>' + $(this).attr('name') + '</b></h3>');
$("#opis").append($(this).find('opis').text());
$("#foto").append('<img src="' + $(this).attr('picture') + '" class="img-thumbnail col-xs-5 col-sm-6 col-md-6 col-lg-4" />');
});
});
}
这样,我无法在页面上显示图像。我的查询有没有错误? 谢谢
答案 0 :(得分:1)
您需要使用find()
获取XML的zdjecie
元素,然后使用attr
获取picture
属性。试试这个:
$("#foto").append('<img src="' + $(this).find('zdjecie').attr('picture') + '" class="img-thumbnail col-xs-5 col-sm-6 col-md-6 col-lg-4" />');