我不知道如何将文本放入强并添加“x”。
<span>something</span> 5
<span>something</span> 4
我想要:
<br /><span>something</span> <strong>5x</strong>
<br /><span>something</span> <strong>4x</strong>
我的解决方案:
$("span").each(function() {
$(this).before("<br />");
$(this.nextSibling).wrapAll("<strong></strong>").after("x");
});
但是输出并不完美:
<br /><span>something</span> <strnong>5 x</strong>
<br /><span>something</span> <strnong>4 x</strong>
如何去掉5和x之间的空格?
最佳答案
尝试
$("span").each(function () {
$(this).before("<br />");
$(this.nextSibling).wrapAll("<strong></strong>").parent().text(function (i, t) {
return t.replace(/\s+$/, '') + 'x'
});
});
演示:Fiddle
关于javascript - 下一个文本换行并添加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23331621/