【发布时间】:2014-06-07 08:46:58
【问题描述】:
我正在解析 xml,我想要的是在解析后返回 xml。 我无法获取图片链接。你能帮助我吗 ?我的代码如下或http://jsfiddle.net/4DejY/2/:
HTML
<ul data-role="listview" data-filter="true" data-filter-placeholder="Search..." id="ds-canho">
javascript
$(document).ready(function () {
$.mobile.loading("show");
$.ajax({
type: "GET",
url: 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url=%27http://saigonpearl.info/trang-chu.html%27%20and%20xpath=%22//td[@class=%27table3%27]/table/tr[2]/td/table/tr/td/table/tr/td/a[contains(@href,%20%27http%27)]%20|%20//div[@class=%27tindang%27]/h3%20|%20//div[@class=%27detailsR%27]/p%22%20%20&diagnostics=true',
dataType: "xml",
success: parseXml
});
function parseXml(xml) {
var gia, img, title;
$(xml).find('p').each(function () {
gia = $(this).text();
title = $(this).prev('h3').text();
$("ul#ds-canho").append('<li><img src="' + img + '">' + title + '<span class="ui-li-count"> ' + gia + '</span></li>')
$('ul#ds-canho').listview('refresh');
console.log(this);
});
$(xml).find("img").each(function () {
img = $(this).find('src').text();
console.log(this);
$.mobile.loading("hide");
});
}
});
【问题讨论】:
-
使用前定义
img
标签: javascript jquery html ajax xml