搜索并替换unicode字符 [英] Search and replace unicode character

查看:84
本文介绍了搜索并替换unicode字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用搜索并替换 jQuery脚本. 我正在尝试将每个字符都放在一个跨度中,但不适用于Unicode字符.

I'm using this search and replace jQuery script . I'm trying to put every character in a span but it doesn't work with unicode characters.

$("body").children().andSelf().contents().each(function(){
    if (this.nodeType == 3) {
        var $this = $(this);
        $this.replaceWith($this.text().replace(/(\w)/g, "<span>$&</span>"));
    }
});

我应该更改节点类型吗?通过什么方式 ?

Should I change the node type ? by what ?

谢谢

推荐答案

将\ w(仅字词字符)替换为". (所有角色)

replace \w (only word caracters) by "." (all caracters)

$("body").children().andSelf().contents().each(function(){
    if (this.nodeType == 3) {
        var $this = $(this);
        $this.replaceWith($this.text().replace(/(.)/g, "<span>$&</span>"));
    }
})

这篇关于搜索并替换unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆