<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);
});