查找并替换超过1个单词? [英] Find and Replace more than 1 word?
本文介绍了查找并替换超过1个单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用jQuery更改页面上的许多不同单词.这是我到目前为止的代码:
I need to change a bunch of different words on a page using jQuery. This is the code I have so far:
(function($) {
var thePage = $("body");
thePage.html(thePage.html().replace([/My Classes/g, 'My Levels'],));
})(jQuery)
如何修改此代码,以便我可以查找和替换更多单词?可以说我也想用猫"代替狗",用女孩"代替男孩".
How do I modify this code so I can find and replace more words? Lets say I also want to replace "dog" with "cat" and "boy" with "girl".
推荐答案
您可以做的是,如果您链接替换值,例如:
What you could do is if you chain the replace values such as:
thePage.html(thePage.html().replace([/My Classes/g, 'My Levels'],))
.replace([/dog/g, 'cat'],))
.replace([/bird/g, 'pen'],));
这是您在jsfiddle中提供的更新的代码
Here is the updated code with what you've provided on jsfiddle
(function($) {
$(function(){
var thePage = $("body");
thePage.html(thePage.html().replace(/My Classes/g, 'My Levels').replace(/dog/g, 'cat').replace(/bird/g, 'pen'));
});
})(jQuery)
还有jsfiddle链接:
And the jsfiddle link:
这篇关于查找并替换超过1个单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文