Jquery查找替换多个单词

标签 jquery replace find words

我正在尝试替换同一 div 中的多个单词。
显然这行不通,这是我的代码。

$("#Number").each(function() {
    var text = $(this).text();
    $(this).text(text.replace("Monster", "Witch")); 
});
$("#Number").each(function() {
    var text = $(this).text();
    $(this).text(text.replace("Girl", "Boy")); 
});

谢谢。

最佳答案

Replace 不能接受多个参数,但您可以将其链接起来,例如:

$("#Number").each(function() {
    $(this).html($(this).html().replace('find1', 'replace1').replace('find2', 'replace2'));
});

关于Jquery查找替换多个单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28611194/

相关文章:

c++ - 在较大的字符串中搜索字符串

jquery - Uncaught ReferenceError : $ is not defined rails

python - file.replace ('abcd' ) 也替换了 'abcde' 如何只替换精确值?

sql - 用 Select 查询替换 While 循环

Python/PyGame : Find pixel by colorcode

c++ - std::find 的优点

javascript - jquery 语法 : where to put "toFixed"

javascript - 禁用 <ul> 问题中的 `<a>` 链接

javascript - 导入 Bootstrap JavaScript、Webpack

regex - 如何用sed插入html标签?