Add a Profile Picture in form in HTML and CSS

前端 未结 4 1967
遇见更好的自我
遇见更好的自我 2020-12-29 12:55

I am creating a form in which I need a Profile picture of the user and I want that the picture is in a circle or a ectangular form. By default the area of image should be bl

4条回答
  •  隐瞒了意图╮
    2020-12-29 13:40

    Insert Image tag separately with default image then read the URL while selecting image through input tag.

    profile-image
    

    function readURL(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();
                
                reader.onload = function (e) {
                    $('#profile').attr('src', e.target.result);
                }
                
                reader.readAsDataURL(input.files[0]);
            }
        }
        
        $("#image").change(function(){
            readURL(this);
            //other uploading proccess [server side by ajax and form-data ]
        });

    Fiddle Link: https://jsfiddle.net/7ao1qxLe/1/

提交回复
热议问题