头像点击预览代码

<style>
   #exampleInputFile {
        display: none;
    }
</style>

  

<div class="form-group">
                    <label for="exampleInputFile">头像
                        <img src="/static/image/1552037426(1).jpg" id="header_image">
                    </label>
                    <input type="file" id="exampleInputFile">
</div>

  

<script>
    $("#exampleInputFile").change(function () {
        var choose_file = $(this)[0].files[0];
        var reader = new FileReader();
        reader.readAsDataURL(choose_file);
        reader.onload = function () {
            $("#header_image").attr("src", reader.result)
        }
    })
</script>

  

 

posted @ 2019-03-12 10:53  CrazyDemo  阅读(438)  评论(1编辑  收藏  举报