Capturing cancel event on input type=file

后端 未结 3 1835
深忆病人
深忆病人 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:03

    There isn't really a listener to check for if a file was selected, you could get around it by setting a note in your code using the on change event like so:

    var FileChoosen = false;
    
    var inputElement = document.getElementById("inputField");
    inputElement.addEventListener("change", handleFiles, false);
    function handleFiles() {
      var fileList = this.files; /* now you can work with the file list */
    
    
      //Check if the layout was changed from file API:
      if(document.getElementById('fileOutput').innerHTML != "") {
        FileChoosen = true;
        setTimeout("funcCalledToCheckUserSelection()", 500);
      };
    
    
    }
    

提交回复
热议问题