【发布时间】:2019-01-06 19:21:36
【问题描述】:
我有
<div class="test">hello everyone</div>
我想改变这个 div 中的每个 hello
<h1>helllo</h1>
例如我用过的
$(this).text().replace("hello", "<h1>hello<h1>");
但它输出
<h1>hello</h1>
我希望它应用为 HTML 而不是文本,我该怎么做?
【问题讨论】:
-
尝试使用 $(this).html() 并以相同的方式设置它
-
试过也没用
-
尝试使用类选择器?
-
$(this).html($(this).html().replace("hello", "<h1>hello</h1>")); -
$(".code").html($(".code").html().replace("int", "<span class='var'>int</span>"));...你写的应该是这个(没有任何包装功能)。