How to check file input size with jQuery?

前端 未结 8 2320
渐次进展
渐次进展 2020-11-22 09:21

I have a form with file upload capabilities and I would like to be able to have some nice client side error reporting if the file the user is trying to upload is too big, is

8条回答
  •  囚心锁ツ
    2020-11-22 09:50

    I found this to be the easiest if you don't plan on submitted the form through standard ajax / html5 methods, but of course it works with anything.

    NOTES:

    var size = $('#uploadForm')["0"]["0"].files["0"].size;
    

    This used to work, but it doesn't in chrome anymore, i just tested the code above and it worked in both ff and chrome (lastest). The second ["0"] is now firstChild.

提交回复
热议问题