在元素内换行 [英] Wrap text within element
本文介绍了在元素内换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将文本用div包裹在div中.
I need to wrap text inside a div with a span.
<div class="item">
<span class="count"></span>
Text that needs to be wrapped.
</div>
<div class="item">
<span class="count"></span>
Text that needs to be wrapped.
</div>
<div class="item">
<span class="count"></span>
Text that needs to be wrapped.
</div>
试过这个,但没有真正起作用...
Tried this but it did not really work...
$('.item').text().wrap('<span class="new" />');
推荐答案
您可以使用 contents()和 .eq()
$('.item').each(function(i, v) {
$(v).contents().eq(2).wrap('<span class="new"/>')
});
这篇关于在元素内换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文