-10

示例我有这段代码:

<div class="description"> I make you smile. </div>

转换为:

<div class="description"> I make you think. </div>

注:“微笑”改为“思考”

如何使用 javascript jQuery 替换它?可以换几个字吗?

4

1 回答 1

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.

.replaceMDN

演示:http: //jsfiddle.net/DerekL/FdyEH/

于 2013-01-12T19:10:51.753 回答