2

我想从 jQuery 中的以下段落中分别获取文本和图像。

<item>
    <title>Brazil 2014: Same old story, different ending</title>
    <category>England</category>
    <category>Euro 2012</category>
    <category>Germany</category>  
    <category>Italy</category>   
    <category>Mario Balotelli</category>
    <category>North End Galactico</category>
    <category>Roy Hodgson</category>   
    <category>Spain</category>
    <dc:creator>Tony Davies</dc:creator>
    <pubDate>Fri, 30 Nov 2012 09:00:48 +0000</pubDate>
    <link>http: 
  //www.footballfriendsonline.com/blogs/2012/11/30/brazil-2014-same-old-story-different- 
  ending.html</link>
    <guid isPermaLink="false">565562:8695411:31453180</guid>
    <description>
        <![CDATA[
            <p>
                <span class="full-image-float-left ssNonEditable">
                    <span>
                        <img src="http://www.footballfriendsonline.com/storage/pictures/premiership/wba/hODGSON.JPG?__SQUARESPACE_CACHEVERSION=1354201352468" alt="" />
                    </span>
                </span>
            </p>
            <p>This summer saw England head to Euro 2012 carrying the hopes of a nation that expected little from their team.</p>
        ]]>
    </description>
    <wfw:commentRss>http://www.footballfriendsonline.com/blogs/rss-comments-entry- 
 31453180.xml</wfw:commentRss></item>

我正在使用它显示空白值。

var container = $(this).find('description').text();
var ctext=$('p',container).text();
var container=container.substr(0,300).replace(/\s+?(\S+)?$/g, '')+suffix;

正是这个容器同时显示了图像和文本。我想在<p>标签中获取文本。

4

1 回答 1

2

The container should be jQuery element/selector, not a text. Try this:

var ctext=$('p',"description").text();

working link http://codepen.io/yardenst/pen/pEtiA

于 2012-11-30T12:41:25.223 回答