关于中文编码转换

作者: amCow | 来源:发表于2017-02-22 22:34 被阅读8次

    常常在一些寻找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>
    

    相关文章

      网友评论

      本文标题:关于中文编码转换

      本文链接:https://www.haomeiwen.com/subject/secvwttx.html