Clear the file upload field in JS (input type = file)

Source: Internet
Author: User
The Value Attribute of the type = file field in the form cannot be attached to the value by JS. Once a file is selected, this value is retained if you do not manually clear it, the corresponding file is also submitted when the form is submitted. of course, it will be verified again on the server. However, to avoid uploading unnecessary files, it is necessary to clear the File Upload fields after the client verification fails in advance.
The specific method is to remove the file element from the Dom and add "Same Name and surname". Below is a section written based on jquery. Code
Function clearupload (){
$ ("# Fuimg"). Remove (); // remove the original
VaR upfile = $ ("<input/>"). ATTR ("name", "fuimg"). ATTR ("ID", "fuimg ");
Upfile. ATTR ("type", "file"). addclass ("w160 ");
Upfile. appendto ("# upload"); // Add a new
Upfile. Change (filechangehandle); // The binding process,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.