【问题标题】:Use jQuery to find and replace multiple words on the page [duplicate]使用jQuery查找和替换页面上的多个单词[重复]
【发布时间】:2012-04-12 02:35:25
【问题描述】:

可能重复:
Find and Replace more than 1 word?

我想使用 jQuery 替换特定单词的所有实例。例如,我想将“My Classes”替换为“My Levels”,将“My Class”替换为“My Level”。我也想把“college”改成“university”

【问题讨论】:

标签: jquery replace


【解决方案1】:

你可以试试这样的:

var dictionary= {
"My Classes":"My Levels",
"My Class":"My Level",
"college":"university"
};

$("body *").each( function(){
    for( var ptrn in dictionary){
        $(this).text( $(this).text().replace(new RegExp(ptrn ,"g"), dictionary[ptrn] ) );
    }
});

【讨论】:

    猜你喜欢
    • 2015-04-21
    • 2012-10-27
    • 2019-03-07
    • 2012-01-04
    • 1970-01-01
    • 2015-06-16
    • 2022-01-03
    • 2021-03-12
    • 2011-12-08
    相关资源
    最近更新 更多