Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在帖子中使用jquery从标题中选择链接_Jquery - Fatal编程技术网

在帖子中使用jquery从标题中选择链接

在帖子中使用jquery从标题中选择链接,jquery,Jquery,条目内容类就在header div之后。 我试过这个: header > h2 > a 但它只选择第一篇文章的链接,而不是每一篇文章的链接 HTML: var src = jQuery('.ovh header h2 a').attr("href"); NP带来了2014年系列的水车和配件,旨在增强骑乘体验,为每位骑手提供舒适、保护和时尚。分享他们40年来对水的痴迷,然后自己决定。www.npsurf.com 迭代.entry content元素,然后找到相关的href并在当

条目内容类就在header div之后。 我试过这个:

header > h2 > a 
但它只选择第一篇文章的链接,而不是每一篇文章的链接

HTML:

var src = jQuery('.ovh header h2 a').attr("href");

NP带来了2014年系列的水车和配件,旨在增强骑乘体验,为每位骑手提供舒适、保护和时尚。分享他们40年来对水的痴迷,然后自己决定。www.npsurf.com


迭代
.entry content
元素,然后找到相关的href并在当前
.entry content

<header>
  <div class="entry-meta post-info">
    <!-- <span class="byline author vcard">By <a href="http://appfessional.com/new/author/admin1/" rel="author" class="fn">Kitejock Team</a>,</span>-->
    <span class="post-tags"><a href="http://appfessional.com/new/tag/canada/" rel="tag">canada</a>&nbsp;<a href="http://appfessional.com/new/tag/gear-2/" rel="tag">gear</a>&nbsp;<a href="http://appfessional.com/new/tag/np/" rel="tag">np</a></span>
    <a href="http://appfessional.com/new/satisfy-your-thirst-with-np-2014-collection/#respond" title="Comment on Satisfy Your Thirst with NP 2014 Collection">Leave a comment</a>
  </div>

  <h2><a href="http://appfessional.com/new/satisfy-your-thirst-with-np-2014-collection/">Satisfy Your Thirst with NP 2014 Collection</a></h2>
</header>

<div class="entry-content">
  <p>NP brings &nbsp;the 2014 collection of waterwear and accessories, all designed to enhance the riding experience and to provide comfort, protection and style to every rider. Share their 40 year obsession for water and decide for yourself. www.npsurf.com</p>
</div>
jQuery('.entry content')。每个(函数(){
var href=$(this.prev('header').find('h2>a').attr('href'),
anchor=$('',{href:href,text:'继续阅读>>'});
$(此)。在(锚定)之后;
});

迭代
.entry content
元素,然后找到相关的href并在当前
.entry content

<header>
  <div class="entry-meta post-info">
    <!-- <span class="byline author vcard">By <a href="http://appfessional.com/new/author/admin1/" rel="author" class="fn">Kitejock Team</a>,</span>-->
    <span class="post-tags"><a href="http://appfessional.com/new/tag/canada/" rel="tag">canada</a>&nbsp;<a href="http://appfessional.com/new/tag/gear-2/" rel="tag">gear</a>&nbsp;<a href="http://appfessional.com/new/tag/np/" rel="tag">np</a></span>
    <a href="http://appfessional.com/new/satisfy-your-thirst-with-np-2014-collection/#respond" title="Comment on Satisfy Your Thirst with NP 2014 Collection">Leave a comment</a>
  </div>

  <h2><a href="http://appfessional.com/new/satisfy-your-thirst-with-np-2014-collection/">Satisfy Your Thirst with NP 2014 Collection</a></h2>
</header>

<div class="entry-content">
  <p>NP brings &nbsp;the 2014 collection of waterwear and accessories, all designed to enhance the riding experience and to provide comfort, protection and style to every rider. Share their 40 year obsession for water and decide for yourself. www.npsurf.com</p>
</div>
jQuery('.entry content')。每个(函数(){
var href=$(this.prev('header').find('h2>a').attr('href'),
anchor=$('',{href:href,text:'继续阅读>>'});
$(此)。在(锚定)之后;
});

如果我理解正确,您的html如下所示:

var src = jQuery('.ovh header h2 a').attr("href");
jQuery('.entry-content').after('<a href="' + src_should_be_here + '">Continue reading >></a>');
jQuery('.entry-content').each(function() {
    var href   = $(this).prev('header').find('h2 > a').attr('href'),
        anchor = $('<a />', {href: href, text: 'Continue reading >>'});

    $(this).after(anchor);
});

这样,您只需在DOM中导航以找到合适的元素。

如果我理解正确,您的html如下所示:

var src = jQuery('.ovh header h2 a').attr("href");
jQuery('.entry-content').after('<a href="' + src_should_be_here + '">Continue reading >></a>');
jQuery('.entry-content').each(function() {
    var href   = $(this).prev('header').find('h2 > a').attr('href'),
        anchor = $('<a />', {href: href, text: 'Continue reading >>'});

    $(this).after(anchor);
});

这样,您只需在DOM中导航以找到合适的元素。

呈现的html是什么样子的?@Sergio查看我的编辑呈现的html是什么样子的?@Sergio查看我的编辑