HTML替换脚本仅替换第一个术语

Jos*_*mas 2 jquery replace

我在日语目录上运行此脚本,用于替换页面上的英语术语,以获取不可自定义的术语的Blog插件.它工作得很好,但它似乎只是在第一次看到它时取代了这个术语.

http://www.martyregan.com/jp/blog/

例如,你会看到View Post,Tags,Feb在底部博客文章中仍然是英文.

这是脚本:

$(document).ready(function(){
            $('#pb_sidebar, #left-sidebar-inner, #pb_body, #main-content-inner, #sidebar-archives').each(function(i){
$(this).html($(this).html().replace('Category List','????????'));
$(this).html($(this).html().replace('Tag List','??'));
})
    })
Run Code Online (Sandbox Code Playgroud)

我怎样才能改变它,以便它在它看到的任何地方抓住它?谢谢!

Llo*_*oyd 5

您需要使用正则表达式,该/g选项将重复,否则string.replace()只运行一次.

例如:

$(this).html($(this).html().replace(/Category List/g,'????????'));
Run Code Online (Sandbox Code Playgroud)