基于jquery读取input上传的文件内容

<script src="/static/js/jquery.js"></script>
    // 前端页面实现头像预览
    // 当用户选中文件之后,也就是头像的input标签有值时触发
    $('#avatar').change(function () {
        var file = this.files[0];
        var fr = new FileReader();
        fr.readAsDataURL(file);
        fr.onload = function(){
            $('#avatar-img').attr('src',fr.result)

        }
    })

 

posted @ 2018-11-10 11:51  dmyHero  阅读(5771)  评论(0编辑  收藏  举报