我有以下内容:
HTML:
<div class="WishListMember_LoginMergeCode">
Killer Idea
<br>
Outsource Course
<br>
App Development
<br>
</div>
我想把它变成这个:
<div class="WishListMember_LoginMergeCode">
<a href="link1">Killer Idea</a>
<br>
<a href="link2">Outsource Course</a>
<br>
<a href="link3">App Development</a>
<br>
</div>
如何实现这一目标?
答案 0 :(得分:1)
$('div.WishListMember_LoginMergeCode').contents().filter(function(){
return this.nodeType === 3;
}).wrap('<a href="#"></a>');
更新
$('div').contents().filter(function() {
return this.nodeType === 3;
}).wrap(function(index) {
return '<a href="link'+ ++index +'"></a>';
});