javascript - 使用 [quote]foo text[/quote] 抓取文本并用 JS 将其替换为 <div class ="quote-text">foo text</div>

标签 javascript jquery

嘿,我有一些格式如下的文本:

[quote]foo text[/quote]

我想把它改成这样:

<div class="quote-text">foo text</div>

如何用 JS 做到这一点?

我正在使用 jQuery。

最佳答案

应该执行以下操作:

string.replace(/\[quote\](.*?)\[\/quote\]/g, "<div class=\"quote-text\">".$1."</div>");

关于javascript - 使用 [quote]foo text[/quote] 抓取文本并用 JS 将其替换为 <div class ="quote-text">foo text</div>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1377266/

相关文章:

javascript - NodeJS 套接字发出返回未定义

javascript - 应用程序脚本格式日期时间错误

c# - 我可以在 Microsoft Visual Studio 2010 中缩小 JavaScript 或 aspx 代码吗

javascript - html anchor 标记的 onclick 不起作用

javascript - CSS 或 Javascript href 悬停(或鼠标悬停)显示额外的可点击链接

jquery - 在 3 行网格中 float div,中间行顶部偏移

javascript - 在angularjs中填充下拉选择

java - 通过表单提交重新加载 struts jqGrid

javascript - 将表格单元格数据转换为单独的 .js 文件中的内部链接

javascript - jQuery : Increase the size of datepicker widget