示例我有这段代码:
<div class="description"> I make you smile. </div>
转换为:
<div class="description"> I make you think. </div>
注:“微笑”改为“思考”
如何使用 javascript jQuery 替换它?可以换几个字吗?
示例我有这段代码:
<div class="description"> I make you smile. </div>
转换为:
<div class="description"> I make you think. </div>
注:“微笑”改为“思考”
如何使用 javascript jQuery 替换它?可以换几个字吗?
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
演示:http: //jsfiddle.net/DerekL/FdyEH/