【发布时间】:2016-10-17 09:28:07
【问题描述】:
我想使用 jQuery 将文本替换为图像。我一直在使用 .replace 函数用更多文本替换文本。如何将文本替换为 html 标记,例如 标记。
这是我的代码:
function wow() {
$('.messageBody').each(function() {
var text = $(this).text();
var image = '<img class = "emote" src = "trump.png">'
$(this).text(text.replace(':trump:', image.outterHTML));
});
}
setInterval(wow, 1000);
这是 HTML:
<span class="messageBody">:trump:</span>
【问题讨论】:
标签: javascript jquery html