上传图片

<div class="portrait">
<img alt="头像" src="img/male.jpg" id="portrait_pic">
<input type="file" accept="image/*">
<input type="hidden" name="portrait_pic">
</div>

$(".portrait input").change(function(){
if(this.files.length==0) {
return;
}
var file = this.files[0];
var reader = new FileReader();
reader.onload = function(e){
$("#portrait_pic").attr("src",e.target.result);
$(".portrait input[name='portrait_pic']").val(e.target.result);
}
reader.readAsDataURL(file);
});

posted @ 2016-08-10 21:10  开心的饭饭  阅读(114)  评论(0编辑  收藏  举报