码迷,mamicode.com
首页 > 编程语言 > 详细

javascript各种方法集

时间:2017-11-28 23:13:49      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:title   func   pre   hang   file   col   cti   get   set   

 

js图片转Base64格式

<!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>

 

javascript各种方法集

标签:title   func   pre   hang   file   col   cti   get   set   

原文地址:http://www.cnblogs.com/shouhe/p/7912622.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!