<img id="head_img" src="./11.jpg" style="width: 100%;height: 100%;" alt="">
<input type="file" name="xx" id="upload_head_img" style="display:none" />
<input type="button" value="修改头像" id="btn" class="btn" style="width: 140px;height: 40px;" onclick="document.getElementById('upload_head_img').click();" />
document.getElementById("upload_head_img").addEventListener("change",(e)=>{
// console.log(e.target.files[0])
var reader = new FileReader();
reader.readAsDataURL(e.target.files[0]);
reader.onload = function(){
// console.log(reader.result);
document.getElementById("head_img").src = reader.result
}
})
实现原生button上传文件
最新推荐文章于 2024-08-05 23:02:44 发布