【问题标题】:Search Text and Replace with JavaScript搜索文本并用 JavaScript 替换
【发布时间】:2012-12-27 03:26:11
【问题描述】:

例如我有这个代码:

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

转化为:

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

注意:“微笑”被替换为“思考”

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

【问题讨论】:

  • 问题表明缺乏事先的搜索努力......这里可能已经有 100 个类似的帖子了

标签: javascript jquery text replace


【解决方案1】:
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/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-22
    • 1970-01-01
    • 1970-01-01
    • 2011-02-20
    • 2010-10-05
    • 2015-01-09
    相关资源
    最近更新 更多