【发布时间】:2014-01-25 19:35:24
【问题描述】:
我想替换,在文本变量中添加一些字符串,以便“包装”我的内容,然后在以后附加它。
例如,我的字符串 var 中有这个(在我的 var 中没有换行符):
[th_section type="boxed" bgcolor="" txtcolor=""]
[th_header type="h1" txtalign="txt-left" subtitle="essai subtitle" txtcolor=""]
HEADER 1
[/th_header]
[th_five_sixths txtalign="txt-left" boxed="" last_column="true"]
[th_header type="h5" txtalign="txt-left" subtitle="" txtcolor=""]
100% Responsive Design
[/th_header]
Phasellus enim libero, blandit vel sapien vitae, condimentum ultricies magna et. Quisque euismod orci ut et lobortis aliquam.
[/th_five_sixths]
[/th_section]
我想像这样替换/添加 p 标签:
<p>[th_section type="boxed" bgcolor="" txtcolor=""]</p>
<p>[th_header type="h1" txtalign="txt-left" subtitle="essai subtitle" txtcolor=""]</p>
<p>HEADER 1</p>
<p>[/th_header]</p>
<p>[th_five_sixths txtalign="txt-left" boxed="" last_column="true"]</p>
<p>[th_header type="h5" txtalign="txt-left" subtitle="" txtcolor=""]</p>
<p>100% Responsive Design</p>
<p>[/th_header]</p>
<p>Phasellus enim libero, blandit vel sapien vitae, condimentum ultricies magna et. Quisque euismod orci ut et lobortis aliquam.</p>
<p>[/th_five_sixths]</p>
<p>[/th_section]</p>
事实上,我可能会搜索如何像这样进行正则表达式:
$someDiv.replace('[th_*******]', '<p>[th_*******]</p>').replace('[/th_*******]', '<p>[/th_*******]</p>')
我不知道在这种情况下使用替换的正确方法是什么。括号之间的名称可以不同,除了 [th_...] 和 [/th_...] 也许我需要使用一个不同于replace的函数,我真的不知道......
【问题讨论】:
标签: jquery string text replace