简体   繁体   中英

Javascript Input Event Fire Twice

I want to upload an Excel file through the browser and I am showing this file. However sometimes there is an error and I need to change some columns in the Excel file and I want to upload the same file. The event is firing just one time because filename is the same. How can I solve this problem? I want to upload the same file and I want the event to fire twice.

document.getElementById('upload').addEventListener('input', handleFileSelect, false);

var handleFileSelect = function(evt) {
  var files = evt.target.files; // FileList object
  var xl2json = new ExcelToJSON();
  xl2json.parseExcel(files[0]);
  console.log(evt)
};
<input id="upload" type=file  name="files[]">

I tried

$("#upload").unbind("input").bind("input",handleFileSelect)

and

document.getElementById('upload').addEventListener('change', handleFileSelect, false)

You should use the onChange event.

var el = document.getElementById('upload');
el.onchange = function() {
  // your code...
};

I solved this problem. I added this code in my function

 evt.target.value = null;

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