我有这个 HTML block :
<div class='translate' id='community_participation'>
Supported by
<span class='notranslate'>
52
</span>
customers like
you, as well as
<a href="/gsfnmichelle/people">the <span class='notranslate'>GSFNMICHELLE</span> team</a>.
</div>
我知道我可以用 $('#community_participation.translate').html('Something here.'); 改变整个事情
但我不知道如何更改跨度之间的文本,即“支持者”、“像您这样的客户以及”、“the”和“团队”。
最佳答案
我建议你使用 jQuery contents()获取文本节点和 wrap它位于新元素中以便于管理:
var el = $('.translate').contents().filter(function() {
return this.nodeType == Node.TEXT_NODE;
}).eq(0).wrap('<span class="newDiv"></span>');
然后您可以使用 text() 更改文本:
$('span.newDiv').text('New Text');
<强> FIDDLE
关于jquery - 使用 jQuery 更改跨度之间的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16151085/