0

我从 rss 提要 url 获取数据,格式如下

 <item><title>NY Fashion Week Series - Christy Turlington - The Model As Muse</title>     
<category>Art</category><category>Obsessions</category>
 <dc:creator>Maria Brito</dc:creator><pubDate>Mon, 09 Sep 2013 04:15:23 +0000</pubDate>
  <link>http://outtherenyc.com/blog/2013/9/7/ny-fashion-week-series-christy-turlington-  
  the-model-as-muse-becoming-art</link>
  <description>   
 <![CDATA[<img data-image-focal-point="0.5,0.5" data-image-dimensions="2277x2448  
  src="http://static.squarespace.com/static/516856a2e4b0f7270653d39d 
 /t/522b5766e4b04879e6b56512
  /1378572144913MariaBrito_Christy_Turlington.JPG?format=500w" 
  />
<img data-image-id="522b7cbbe4b0832d81b4fefe" data-image-focal-point="0.5,0.5" 
data-image-dimensions="489x693" alt="First Eternity campaign shot by Bruce Weber in 
1989" data-load="false" src="http://static.squarespace.com/static
/516856a2e4b0f7270653d39d/522b7cabe4b0d7cf73eb08f5/522b7cbbe4b0832d81b4fefe
/1378582251145/Christy-Eternity.jpg?format=500w" />
  ]]></description></item> 

有多个图像进入。我只想要第一张图片。我已经解析了标题和网址。但在图像的情况下,它显示为空。我正在使用以下代码。

 <script type="text/javascript">
$(document).ready(function() {
 $.get("http://outtherenyc.com/blog?format=rss", function (data) {
var resultsA="";
 var i;        
$(data).find('item').each(function(i){
alert(i);
 var container2 = $(this).find('description').text().replace('<![CDATA[','');  
var title = $(this).find('title').text();
var url = $(this).find('link').text();
 var img_url = $('img', container2).attr('src');


 if(i>2 && i<=5){
 alert(img_url);
 resultsA += '<a href="'+url+'" target="_blank" ><div class="title"><b>'+title+'</b>   
  </a></div>';

   }                 
  });
  $('#Getfeed').html(resultsA); 

 });
 });
</script>
<div id="Getfeed"></div>

请让我知道如何仅解析第一个图像网址?

4

1 回答 1

0

使用休息;或返回;在你找到你要找的东西之后。

http://api.jquery.com/each/

于 2013-09-09T06:18:42.557 回答