JavaScript本地图片文件预览

<body>
<input type="file" accept="image/*" onchange="loadFile(event)" />
<img id="previewContainer" src="" alt=""/>

<script>
    const output = document.querySelector("#previewContainer");
    const loadFile = function (event) {
        const reader = new FileReader();
        reader.onload = function () {
            console.log(reader);
            output.src = reader.result;
        };
        reader.readAsDataURL(event.target.files[0]);
    };
</script>
</body>
posted @ 2020-07-21 11:05  demo_you  阅读(233)  评论(0编辑  收藏  举报