使用JS 最简单的代码进行text 到 base64 的转换,可以使用如下链接
https://aqwu.net/tools/base64.html
源代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
<!DOCTYPE html> <html lang="cn"> <head> <title>base64 - 杰力皓博</title> <meta charset="utf-8" /> <meta name="referrer" content="same-origin" /> <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <meta name="keywords" content="base64,杰力皓博"> <style> .center { margin: auto; width: 300px; border: 3px solid #73AD21; padding: 10px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); border-radius: 15px; background: #f0f0f0; } textarea { width: 290px; } </style> </head> <body> <div class="center"> <center> <h1>Base64</h1> <hr/> <table> <tr> <td>text:</td> </tr> <tr> <td> <textarea id="text" type="textarea" rows="10" placeholder="text"/></textarea> </td> </tr> <tr> <td>base64:</td> </tr> <tr> <td> <textarea id="base64" type="textarea" rows="10" placeholder="base64"></textarea> </td> </tr> </table> <hr/> <table> <tr> <td><input id="encod" type="button" value="Encode" onclick="encodedData()"/></td> <td><input id="decoded" type="button" value="Decode" onclick="decodedData()"/></td> </tr> </table> </center> </div> <script type="text/javascript"> function encodedData() { // 编码 base64.value = window.btoa(unescape(encodeURIComponent(text.value))); } function decodedData() { // 解码 text.value = decodeURIComponent(escape(window.atob(base64.value))); } window.onload=function() { text.value = ""; base64.value = ""; } </script> </body> </html> |