雑だけど、こんな感じ(´ω`)
<html> <body> <input type="file" id="myImage" accept="image/*" onchange="setImage(this);" onclick="this.value = '';"> <img id="preview"> <script> function setImage(target) { var reader = new FileReader(); reader.onload = function (e) { document.getElementById("preview").setAttribute('src', e.target.result); } reader.readAsDataURL(target.files[0]); }; </script> </body> </html>
以上!!