图片上传在线预览
<input type="file" accept="image/*" onchange="showMyImage(this)" /> <br/> <img id="thumbnil" style="width:20%; margin-top:10px;" src="" alt="image"/>
function showMyImage(fileInput) { var files = fileInput.files; for (var i = 0; i < files.length; i++) { var file = files[i]; var imageType = /image.*/; if (!file.type.match(imageType)) { continue; } var img=document.getElementById("thumbnil"); img.file = file; var reader = new FileReader(); reader.onload = (function(aImg) { return function(e) { aImg.src = e.target.result; }; })(img); reader.readAsDataURL(file); } }