123456789101112131415161718192021222324252627282930313233 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>Document</title>
- </head>
- <body>
- <input type="file" onchange="previewFile()" /><br />
- <img src="" height="200" alt="Image preview..." />
- <!-- // -->
- <!-- -->
- <script>
- function previewFile() {
- var preview = document.querySelector("img");
- var file = document.querySelector("input[type=file]").files[0];
- var reader = new FileReader();
- console.log(preview, file, reader);
- reader.onloadend = function () {
- preview.src = reader.result;
- };
- if (file) {
- reader.readAsDataURL(file);
- } else {
- preview.src = "";
- }
- }
- </script>
- </body>
- </html>
|