我需要使用 jQuery 更改页面上的一堆不同的单词。这是我到目前为止的代码:
(function($) {
var thePage = $("body");
thePage.html(thePage.html().replace([/My Classes/g, 'My Levels'],));
})(jQuery)
如何修改此代码以便可以查找和替换更多单词?可以说我还想用“猫”替换“狗”,用“女孩”替换“男孩”。
您可以做的是,如果链接替换值,例如:
thePage.html(thePage.html().replace([/My Classes/g, 'My Levels'],))
.replace([/dog/g, 'cat'],))
.replace([/bird/g, 'pen'],));
EDIT:
这是您在 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 链接:
http://jsfiddle.net/BEftd/4/ http://jsfiddle.net/BEftd/4/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)