js 将 unicode编码转换中文2种方式

JavaScript08

js 将 unicode编码转换中文2种方式,第1张

1、网上有工具

2、带/u 或者%u的是unicode编码结果

3、转中文方式

详细:

unescape() 函数可对通过 escape() 编码的字符串进行解码,已废弃。

编码和解码一一对应关系

escape() 编码, unescape() 解码 废弃

encodeURI 编码,decodeURI 解码

encodeURIComponent 编码,decodeURIComponent 解码

用什么解码对应的文件内容

需要准备的材料分别有:电脑、html编辑器、浏览器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<script>标签,输入js代码:。

var a = '测试内容'

document.body.innerText = toUnicodeFun(a)

function toUnicodeFun(data){

if(data == '' || typeof data == 'undefined') return '请输入汉字'

var str =''

for(var i=0i<data.lengthi++){

str+="\\u"+data.charCodeAt(i).toString(16)

}

return str

}

3、浏览器运行index.html页面,此时中文“测试内容”被js成功转码。