js实现上传图片转成beats64

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>upload</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>
 
 
 
摘自:https://www.cnblogs.com/Strom-HYL/p/6782176.html
posted @ 2019-02-12 11:20  IT小菜鸟1  阅读(298)  评论(0编辑  收藏  举报