XML:
<item>
<title>Some title</title>
<description>
<![CDATA[
Some description text Some description text Some description text Some description text Some description text Some description text
Some description text Some description text Some description text Some description text Some description text Some description text
Some description text Some description text Some description text Some description text Some description text Some description text
Some description text Some description text Some description text Some description text Some description text Some description text
]]>
</description>
<media:content isDefault="true" medium="image" url="http://sampledomain.com/image.jpg">
<media:title>Image title</media:title>
<media:description>Image description</media:description>
<media:thumbnail url="http://sampledomain.com/image.jpg" width="160" height="120" />
</media:content>
<wfw:commentRss>http://sampledomain.com/comment/feed/</wfw:commentRss>
<slash:comments>0</slash:comments>
</item>
我正在从 ajax 获取 css,在 onsuccess 函数中我的代码如下:
$(xml).find('item').each(function() {
var title = $(this).find('title').eq(0).text();
var url = $(this).find('content').attr('url');
// Printing url as undefined
alert(url);
console.log($(this).find('content');
});
我想要获取的内容 url 属性我正在获取项目子项(标题、描述、内容、commentRss 和评论) 但是当我尝试获取 $(this).find('content') 时,它没有给我任何东西 谁能弄清楚我做错了什么? 谢谢
最佳答案
关于jQuery XML解析如何获取元素属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4825920/