HTML选择文件的实时预览
目录
- HTML选择文件的实时预览
- HTML代码
- JS代码
- 预览
HTML代码
<input type="file" id="adv_img_input" style="width: 1000px ;height:30px">
<img src="#"id="adv_img">
JS代码
<script>
const adv_img_input = document.getElementById('adv_img_input')
const adv_img = document.getElementById('adv_img')
adv_img_input.addEventListener('change',function (){const file = adv_img_input.files[0]if (file){const reader = new FileReader()reader.onload = function (e){adv_img.src = e.target.resultconsole.log(adv_img)}reader.readAsDataURL(file)}
})
</script>