打赏

JavaScript字符编解码

示例代码

<!DOCTYPE html>
<html lang="zh">

    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>JavaScript字符串编解码</title>
    </head>

    <body>
        <script>
            var str = 'a';
            //字符的 Unicode 编码
            var unicode = str.charCodeAt(0);
            console.log(unicode);
            //字符解码
            var strNew = String.fromCharCode(unicode);
            console.log(strNew);
        </script>
    </body>

</html>

 

posted @ 2018-03-26 12:02  孟繁贵  阅读(833)  评论(0编辑  收藏  举报
TOP