JS上傳圖片轉化成Base64編碼demo


<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <input accept="image/*" name="upimage" id="upload_file" type="file"> <textarea id="base64_output" name="Word" style=" width:820px"></textarea> <script type="text/javascript"> document.getElementById("upload_file").onchange = function () { gen_base64(); }; function $_(id) { return document.getElementById(id); } function gen_base64() { var file = $_('upload_file').files[0]; r = new FileReader(); //本地預覽 r.onload = function(){ $_('base64_output').value = r.result; } r.readAsDataURL(file); //Base64 } </script> </body> </html>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM