我正在尝试替换同一 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/