How to validate a file upload field using Javascript/jquery

前端 未结 6 964
伪装坚强ぢ
伪装坚强ぢ 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:16

    Check it's value property:

    In jQuery (since your tag mentions it):

    $('#fileInput').val()
    

    Or in vanilla JavaScript:

    document.getElementById('myFileInput').value
    

提交回复
热议问题