<div id="div1">
<input type="file" id="uploadfile" style="width: 100px; height: 25px;" />
<input id="b1" type="button" value="上传" style="display: inline-block; width: 40px; height: 25px;" />
<img id="img1" src="" />
</div>
window.onload = function () {
document.getElementById("uploadfile").addEventListener("change", function () {
//1、获取所选的文件 暂时只选一个 var filereader = new FileReader();
filereader.onloadend = function (event) {
console.log("a");
var filedata = event.target.result;
document.getElementById("img1").src = filedata;
} var file = document.getElementById("uploadfile").files[0];
filereader.readAsDataURL(file);
}, true);
}