在我的
<td>
标签中,有几个-.
。我想做的是,在这个特定单词前面加上<br>
标签。 我使用了replace()
函数,但它只更改了一个-.
。如何找到所有的-.
实例?
原始文本
Lorem Ipsum is simply dummy text of the printing and typesetting industry. -.Lorem Ipsum has been the industry's standard dummy text ever since the 1500s. -.It has survived not only five centuries, but also the leap into electronic typesetting.
我想要的
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
-. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
-. It has survived not only five centuries, but also the leap into electronic typesetting.
这是我的代码示例
<table class="Notice">
<thead>
<tr>
<th>Name</th>
<th>Number</th>
</tr>
<thead>
<tbody>
<tr>
<td>Lorem Ipsum is simply dummy text of the printing and typesetting industry. -.Lorem Ipsum has been the industry's standard dummy text ever since the 1500s. -.It has survived not only five centuries, but also the leap into electronic typesetting.</td>
</tr>
</tbody>
</table>
Javascript
$('td:contains("-.")').html(function (i, htm) {
return htm.replace(/-./g, "<br>-.");
});
解决方案
我发现我的错误 - 我没有处理“每个”单词。因此,我使用了each()
函数,它完美地运行!
$('td:contains("-.")').each(function () {
$(this).html($(this).html().replace(/-./g, "<br>-."));
});
-.
部分。 - naanace