How to validate a file upload field using Javascript/jquery

前端 未结 6 953
伪装坚强ぢ
伪装坚强ぢ 2021-02-07 03:54

How can I validate if the user has selected a file to upload?

Edit: bumped

6条回答
  •  你的背包
    2021-02-07 04:20

    In Firefox at least, the DOM inspector is telling me that the File input elements have a property called files. You should be able to check its length.

    document.getElementById('myFileInput').files.length
    

提交回复
热议问题