<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <input type="file" ><br> <img src="" height="200" alt="Image preview..."> <script> var file = document.querySelector('input[type=file]'); var img = document.querySelector('img'); file.onchange = function(){ var fr = new FileReader(); fr.onload = function(){ img.src = fr.result; } if (file.files[0]){ fr.readAsDataURL(file.files[0]) } } </script> </body> </html>
评论已关闭!