Home > Article > Web Front-end > Solution to clear file domain using jQuery_jquery
Generally speaking, after using validation on a file field (input type="file"), we always want to clear the value in the file field (otherwise the wrong file will still be submitted), and in IE , the reason for the security settings is that the value of the file field is not allowed to be changed (that is, val("") cannot be used)
Then obviously, we can only change our thinking and copy this input element. Then delete the original one.
When copying elements under IE, the values will not be copied, so the purpose of clearing the file field is achieved.
Under Firefox, the values will also be copied together, so we can clear it by the way to achieve compatibility.
The code is as follows: