1

I met some questions about javascript in IE11; the code below is a simple demo:

<input type="file" id="test">
<script>
    document.querySelector("#test").addEventListener("change", function() {
    console.log("file changed");
    });
</script>

when I click the input button, all browsers pop up the file selection window. when I picked file(s) and press "open" (or "confirm" or something else), I see "file changed" message in the console.

after that, when I use command like this below:

document.querySelector("#test").value = "";

chrome, firefox and IE10 do nothing, but IE11 shows "file changed"; so I want to know if this is a bug or just something I got wrong to make this happend. thanks. P.S. I have some way to resolve or circumvent the problem, I just want to know the reason.

孟子易
  • 373
  • 1
  • 4
  • 15
  • Possible duplicate of [How can I clear an HTML file input with JavaScript?](https://stackoverflow.com/questions/1703228/how-can-i-clear-an-html-file-input-with-javascript) – dharmesh Jul 12 '17 at 05:46
  • I know how to resolve ( or circumvent ) this problem, I'm want to know what cause the question. – 孟子易 Jul 12 '17 at 06:18
  • 1
    All browser use different engine to run JavaScript code. It's not like Java which has its own compiler and always produce same result. That's the only reason few JavaScript code don't work on some browser. Ans: IE11 may be handling this as value change and other browser don't. – dharmesh Jul 12 '17 at 06:28
  • Different browsers do not always agree whether a change event should be fired for certain types of interaction: [change event](https://developer.mozilla.org/zh-CN/docs/Web/Events/change) – aspark Jul 12 '17 at 07:01
  • @孟子易 I am having a similar issue? How did you resolve the problem? – Helen Araya Aug 21 '20 at 00:00

0 Answers0