前端开发社区用力学习

关于中文编码转换

2017-02-22  本文已影响8人  amCow

常常在一些寻找BUG的时间中浪费太多精力,不妨记住经常会用到的编码转换,中文编码转换

1、encodeURIComponent() 中文转码
语法 encodeURIComponent(URIstring)
举例:

<script>
        let str = '张三',
        str2 = encodeURIComponent(str);
        alert(str2);/结果:/%E5%BC%A0%E4%B8%89
</script>

2、decodeURIComponent() 转码中文

<script>
    let str = '张三',
    str2 = decodeURIComponent(str);
    alert(str2);//张三
</script>
上一篇 下一篇

猜你喜欢

热点阅读