移除ASCII码«或者,raquo;JavaScript中的字符串

Removing ASCII « OR » from a string in JavaScript

本文关键字:raquo JavaScript 字符串 或者 ASCII laquo 移除      更新时间:2023-09-26

我正在尝试删除«或»

Have try this to no effect:

$('body').delegate('.SearchPagination > a', 'click', function(e){
    e.preventDefault();
    var $this = $(this),
        txt = $this.text().toLowerCase(),
        txt = txt.replace(/«|»/g, ''),
        txt = $.trim(txt),
        page = '&page=';
        console.log(txt);
    if (txt === 'next' || txt === 'previous'){
        // get the current page value
        var active = $this.parent().find('.active').txt();
        if (txt === 'next'){
            // add one
            page += (active + 1);   
        } else if (txt === 'previous'){
            // subtract one
            page += (active - 1);
        }
    } else {
        // invoke search with the page number
        page += txt;
    }
    console.log(page);  
    //icisSite.icisSearch.search(page);
});

不使用«在正则表达式中,尝试复制粘贴浏览器中显示的左箭头字符-即«的迹象。我试了一下,它被正确地替换了。
所以你的正则表达式应该看起来像-

 txt = txt.replace(/«|»/g, '')

你试过了吗:

txt = txt.replace('«','').replace('»', '');

但我不认为这是点,因为你的regexp是正确的,所以,以防万一(你正则表达式对我来说似乎是正确的),你是shure,当你得到文本的htmlentities在第一个地方编码?也许页面是UTF-8格式,实体没有编码,但显示时没有编码