替换单词Jquery,只有一次



我有这个javascript,但每次我在我的网站上保存语言时,都会添加 在最后一个"0"示例"Italiano"上,如果我保存我的个人资料一次更多,脚本会添加另一个"0",例如"Italianoo",如果我再次保存"Italianooo">

y如何解决这个问题? 也没有字典

非常感谢

var dictionary = {
"Afrikanns": "Africano",
"Albanian": "Albanese",
"Arabic": "Arabo",
"Armeno": "Armenian",
"Basque": "Basco",
"Bengali": "Bengalese",
"Bielorussian": "Bielorusso",
"Bulgarian": "Bulgaro",
"Catalan": "Catalano",
"Cambodian": "Cambogiano",
"Czech": "Ceco",
"Cinese": "Cinese",
"Korean": "Coreano",
"Croatian": "Croato",
"Danish": "Danese",
"Hebrew": "Ebraico",
"Estonian": "Estone",
"Fijan": "Fiji",
"Finnish": "Finlandese",
"French": "Francese",
"Georgian": "Georgiano",
"Japanese": "Giapponese",
"Javanese": "Giavanese",
"Greek": "Greco",
"Gujarati": "Gujarati",
"Hindi": "Indiano",
"English": "Inglese",
"Indonesian": "Indonesiano",
"Irish": "Irlandese",
"Icelandic": "Islandese",
"Italian": "Italiano",
"Latin": "Latino",
"Latvian": "Lettone",
"Lithuanian": "Lituano",
"Macedonian": "Macedone",
"Malayalam": "Malayalam",
"Maltese": "Malese",
"Maori": "Maori",
"Marathi": "Marathi",
"Mongolian": "Mongolo",
"Nepali": "Nepalese",
"Norwegian": "Norvegese",
"Dutch": "Olandese",
"Persian": "Persiano",
"Polish": "Polacco",
"Portoguese": "Portoghese",
"Punjabi": "Punjabi",
"Quechua": "Quechua",
"Romanian": "Rumeno",
"Russian": "Russo",
"Samoan": "Samoan",
"Serbian": "Serbo",
"Slovak": "Slovacco",
"Slovenian": "Sloveno",
"Spanish": "Spagnolo",
"Swedish": "Svedese",
"Swahili": "Swahili",
"Thai": "Tailandese",
"Tamil": "Tamil",
"Tatar": "Tatar",
"German": "Tedesco",
"Telugu": "Telugu",
"Tibetan": "Tibetano",
"Tonga": "Tonga",
"Turkish": "Turco",
"Ukranian": "Ucraino",
"Hungarian": "Ungherese",
"Urdu": "Urdu",
"Uzbek": "Uzbeko",
"Vietnamese": "Vietnamita",
"Welsh": "Welsh",
"Xhosa": "Xhosa"
};
jQuery(".upme-field-value > span").each(function() {
for (var ptrn in dictionary) {
jQuery(this).text(jQuery(this).text().replace(new RegExp(ptrn, "g"), dictionary[ptrn]));
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="upme-field-value">
<span>Italian</span>
</div>

您正在搜索单词边界b

console.log("Italian".replace(/bItalianb/g, 'Italiano'))
console.log("Italiano".replace(/bItalianb/g, 'Italiano'))

相关内容

  • 没有找到相关文章

最新更新