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);
}
}