简体   繁体   中英

JS for clearing <input type = “file”> selections

Once the user chooses the file, I have a condition using html5 file api to check if the file size exceeds a 1mb.

function handleLimit(evt) {
   var files = evt.target.files; 
   f = files[0];
   console.log(f.size);
   if (f.size > 1048576) {
          /*JS for clearing form*/
   }
}

What would be the script I would want to run on my input tag to clear/ force the client to choose another file it once the handler knows that file is exceeding a certain size?

 var _fileuploadcontrolId = document.getElementById("id");
            _fileuploadcontrolId.value = "";
            _fileuploadcontrolId.focus();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM