我想在结束标记 </a>
处显示“href”属性的值对于每个 anchor 标记。
相反,此代码仅适用于页面上的第一个链接。
jQuery.noConflict();
jQuery(document).ready(function($) {
$('a').after($('a').attr('href'));
})(jQuery);
最佳答案
您需要以不同的方式调用该函数:
Type: Function( Integer index, String html ) => htmlString or Element or Text or jQuery A function that returns an HTML string, DOM element(s), text node(s), or jQuery object to insert after each element in the set of matched elements. Receives the index position of the element in the set and the old HTML value of the element as arguments. Within the function, this refers to the current element in the set.
通过这种方式,对于每个 anchor ,您可以将要打印的正确文本返回到 after 方法:
$('a').after(function(idx, txt) {
return this.getAttribute('href');
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="url1">link text</a>
<a href="url2">link text</a>
<a href="url3">link text</a>
<a href="url4">link text</a>
关于jquery - 如何在 "href attribute"之后添加 "</a>",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51900749/