js中base64获取

js获取base64


js代码

function sub(){
            var myfile = document.getElementById("myfile").files[0];
            console.log(myfile);
            var fileRead = new FileReader();
            fileRead.readAsDataURL(myfile);
            fileRead.onload = function(e){
                console.log(e);
                var base64 = e.target.result;
                console.log(base64);
                var img = new Image();
                img.src = base64;
                img.width = "200";
                document.getElementsByTagName("body")[0].appendChild(img);
            }
        }

你可能感兴趣的:(js中base64获取)