Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.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
Javascript 使用jquery添加一个";阅读更多“;基于另一个链接的链接_Javascript_Jquery - Fatal编程技术网

Javascript 使用jquery添加一个";阅读更多“;基于另一个链接的链接

Javascript 使用jquery添加一个";阅读更多“;基于另一个链接的链接,javascript,jquery,Javascript,Jquery,我试图在包含rdm1的段落中添加一个read more链接,该链接包含h2链接到的任何内容的链接。下面是我的HTML和Javascript。我可以添加阅读更多。我无法添加h2的链接。有什么建议吗 <div class="divgrey"> <h2><a href="http://www.example.com">This is a heading.</a></h2> <p>This is some text about

我试图在包含rdm1的段落中添加一个read more链接,该链接包含h2链接到的任何内容的链接。下面是我的HTML和Javascript。我可以添加阅读更多。我无法添加h2的链接。有什么建议吗

 <div class="divgrey">
 <h2><a href="http://www.example.com">This is a heading.</a></h2>

<p>This is some text about the heading. </p>
 <p class="rdm1"></p>
</div>

这是一些关于标题的文字

代码:

$(文档).ready(函数(){
$('.divgrey>p.rdm1').append('readmore');
$('a.rdm')。每个(函数(){
var lnk=$(this.parent().simbines('a').attr('href');
$(this.attr('href',lnk);
});
});
试试这个:

$( document ).ready( function() {

    $( '.rdm1' ).each( function() {
       $( this ).append( '<a href="' + $( this ).closest( '.divgrey' ).find( 'h2 a' ).attr( 'href' ) + '" class="rdm">Read More</a>' );
    });

});
$(文档).ready(函数(){
$('.rdm1')。每个(函数(){
$(此)。附加(“”);
});
});
$( document ).ready( function() {

    $( '.rdm1' ).each( function() {
       $( this ).append( '<a href="' + $( this ).closest( '.divgrey' ).find( 'h2 a' ).attr( 'href' ) + '" class="rdm">Read More</a>' );
    });

});