Capturing cancel event on input type=file

后端 未结 3 1826
深忆病人
深忆病人 2021-02-09 10:44

I have a html5 application that makes use of the file API, using an element. I am able to respond when the user selects a file. I would like to be able to do something if the u

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-09 11:24

    When user clicks cancel, change event triggers again. Thats works for me;

            $('#attachedFiles').bind("change", function () {
                var file = this.files[0];
                if (file) {
                    // if file selected, do something
                } else {
                    // if user clicks 'Cancel', do something
                }
            });
    

提交回复
热议问题