Home  >  Q&A  >  body text

javascript - Regarding input="file", the change event is not triggered when the same file is selected repeatedly

The normal idea is to clear the input content every time after getting the input file. I searched on Baidu and found that some methods use the reset of the form, but what if it is just a separate input="file" without the from element? Moreover, some of the methods found online have poor compatibility. Do experienced drivers have any reliable methods?

I just saw this method, how is the compatibility?

学习ing学习ing2685 days ago1087

reply all(2)I'll reply

  • 欧阳克

    欧阳克2017-06-14 10:54:52

    input.addEventListener('click', function() {
        this.value = '';
    }, false);

    reply
    0
  • 学习ing

    学习ing2017-06-14 10:54:52

    Several ideas:
    1. Set the value of input to '', the same as above.
    2. Replace the current input with a new input
    3. Remove the value attribute of the input.

    reply
    0
  • Cancelreply