选择头像并预览
作者:
方_糖 | 来源:发表于
2019-04-28 10:12 被阅读0次1.实现效果
2.代码
<div class="box">
<img src="car.png" alt="" id="carImg">
<div class="mask">
<a href="javascript:;">上傳圖片</a>
<input type="file" name="" id="file" onchange="selectPic(this)" accept="image/png, image/jpeg, image/jpg">
</div>
</div>
function selectPic() {
var reads= new FileReader();
f=document.getElementById('file').files[0];
reads.readAsDataURL(f);
reads.onload=function (e) {
document.getElementById('carImg').src=this.result;
};
}
本文标题:选择头像并预览
本文链接:https://www.haomeiwen.com/subject/ywgrnqtx.html
网友评论