【发布时间】:2012-07-16 11:06:21
【问题描述】:
我想将纯文本(例如)[next 1272] 替换为
<a href='page.asp?id=1272'>
<img src='next.png' alt='Next Page' title='Next Page' />
</a>
文本可以出现在页面 html 中的任何位置,并且不止一次,可能使用不同的数字(从 1 到 99999)。我无法控制它可能出现的方式/位置。
顺着
var ThisBody = $("body").html()
var regex = new RegExp("\\[ (I dont know) \\]", "g");
StrToReplaceWith = "...(the html in the example, with correct number)..."
ThisBody = ThisBody.replace(regex,StrToReplaceWith);
$("body").html(ThisBody);
【问题讨论】:
标签: javascript regex wildcard