文件上传前预览
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <div id="preview"></div> <input type="file" /> <img src="" alt=""> <script type="text/javascript"> $("input").onchange = function(e) { var file = e.target.files; var reader = new FileReader(); reader.onload = function(evt) { $('img').src = evt.target.result; } reader.readAsDataURL(file[0]); } function $(id) { return document.getElementsByTagName(id)[0]; } </script> </body> </html>