How to check image size (ex. 1MB) before uploading

后端 未结 1 1250
小蘑菇
小蘑菇 2020-12-29 18:07

Is there any way to check the image size before sending the form?

I\'m using jquery.form

js:

$(document).ready(function() {
    var options =         


        
1条回答
  •  我在风中等你
    2020-12-29 18:37

    I answer my own question:

        $(document).ready(function() {
            $('#id_image').bind('change', function() {
                if(this.files[0].size > 1000141){
                    $('#formerror').html('File is too big');
                    $('#myformbutton').hide();
                }else{
                    $('#formerror').html(' ');
                    $('#myformbutton').show('slow');
                }
            });
        });
    

    And html:

            

    This works.

    0 讨论(0)
提交回复
热议问题