js中base64获取
2017-12-27 本文已影响0人
浅夏_cd06
js获取base64
<input type="file" id="myfile" onchange="sub()"/>
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);
}
}