<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JavaScript的base64字符测试</title>
</head>
<body>
<script>
    var str = 'javascript';

    console.log(window.btoa(str));
    //转码结果 "amF2YXNjcmlwdA=="

    console.log(window.atob("amF2YXNjcmlwdA=="));
    //解码结果 "javascript"
    
    var str = "China,中国";
    
    console.log(window.btoa(window.encodeURIComponent(str)));
    //"Q2hpbmElRUYlQkMlOEMlRTQlQjglQUQlRTUlOUIlQkQ="

    console.log(window.decodeURIComponent(window.atob('Q2hpbmElRUYlQkMlOEMlRTQlQjglQUQlRTUlOUIlQkQ=')));
    //"China,中国"
    console.log(window.btoa(str));
    
</script>
</body>
</html>
Last modification:January 9, 2020
如果觉得我的文章对你有用,请随意赞赏