Loading an image to a >

后端 未结 6 850
闹比i
闹比i 2020-11-30 23:06

I\'m trying to load an image selected by the user through an element.

I added a onchange event handler to the input element like this:



        
6条回答
  •  被撕碎了的回忆
    2020-11-30 23:41

    $('document').ready(function () {
        $("#imgload").change(function () {
            if (this.files && this.files[0]) {
                var reader = new FileReader();
                reader.onload = function (e) {
                    $('#imgshow').attr('src', e.target.result);
                }
                reader.readAsDataURL(this.files[0]);
            }
        });
    });
    
    
    

    That works for me in jQuery.

提交回复
热议问题