//html结构
<input id='myFile' onchange='getFileContent()'>
<img src='' id='re_img'>
//js代码
function getFileContent() {
var reader = new FileReader();
var file = document.querySelector("#myFile").files;
reader.readAsDataURL(file[0]);
reader.onload = function() {
//展示
document.getElementById('re_img').src = reader.result;
localStorage.setItem('receipt', reader.result);
console.log(localStorage);
//console.log(document.getElementById('expense'));
}
};
网友评论