Home > Web Front-end > JS Tutorial > Solution to clear file domain using jQuery_jquery

Solution to clear file domain using jQuery_jquery

WBOY
Release: 2016-05-16 17:37:15
Original
2002 people have browsed it

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:

Copy code The code is as follows:

var file = $("#file")
file.after(file.clone().val(""));
file.remove();
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template