<!DOCTYPE html> <html> <head> <meta charset="gbk"> <title></title> </head> <body> <input accept="image/*" name="upimage" id="upload_file" type="file" onchange="gen_base64()"> <br/> <textarea id="base64_output" name="Word" style=" width:820px"></textarea> <br/> <img src="" id="myImg" /> <script type="text/javascript"> 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; $_('myImg').src= r.result; } r.readAsDataURL(file); //Base64 } </script> </body> </html>
以上就是JS获取图片base64值的详细内容,更多关于JS获取图片base64值的资料请关注九品源码其它相关文章!