示例我有这段代码:
<div class="description"> I make you smile. </div>
转换为:
<div class="description"> I make you think. </div>
注意:“微笑”被替换为“思考”
如何使用javascript jQuery替换它?可以改变几个单词吗?
答案 0 :(得分:4)
var ele = $("div.description"); //Let ele be target element
ele.html(ele.html().replace(/smile/gi,"think")); //Replace the word in string,
// then put it back in.
.replace
:MDN