我有:
<a class='special' href='#'>something</a>
<a class='special' href='#'>anything</a>
我需要通过页面加载来实现:
<a class='special' href='something'>something</a>
<a class='special' href='anything'>anything</a>
类似于:
$('a.special').attr('href', $(this).text());
如何做到这一点?
最佳答案
您可以在集合上运行 each()
,这会将 href 设置为文本,但更优雅的方式是给出 function as the second parameter for attr()
.
$('a.special').attr('href', function () {
return $(this).text();
});
关于jquery - 使用 jQuery 根据链接文本设置链接 href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8163824/