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和onsuccess函数中获取css,我的代码如下:
$(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’)它并没有给我任何东西
任何人都可以弄清楚我做错了什么?
谢谢
解决方法
您的XML使用命名空间.
请参阅有关命名空间的类似Stack Overflow问题.你必须逃脱冒号: