【发布时间】:2015-05-16 23:12:24
【问题描述】:
这是替换文本script。
我这样称呼它:
$(document).ready(function() {
$('#test-id').replaceText(/\[this\]/g,'<b>').replace(/\[\/this\]/g,'</b>');
});
它应该只加粗[this] bold text [/this],HTML如下:
<span id="test-id"> [this] This is some text that contains [/this] red color with bold text</span>
它应该只在这个 [this][/this] 内加粗文本,但问题是它也会使其他文本加粗,而不是隐藏最后一个 [/this] 。
我也试过叫这个:
$('#test-id').replaceText(/\[this\]/g,'<b>');
所以请建议如何只替换[this] This is some text that contains [/this],而不是其他文本并隐藏最后一个[/this]。
请看小提琴:http://jsfiddle.net/vw5b1szm/1/
谢谢。
【问题讨论】:
标签: jquery html text replace replacewith