Use jquery to clear the file domain solution _jquery

Source: Internet
Author: User
For example, after you have used validation on a file field (input type= "file"), we always want to empty the value in the File field (otherwise the wrong file will still be submitted), but in IE, the reason for security is not to allow changes to the value of the file field (that is, Val ("") cannot be used. )

So obviously, we can only change the idea of this INPUT element to copy one, and then delete the original.
When the elements are copied in IE, the values are not replicated, so the goal of emptying the file domain is achieved.
And in Firefox, where the value will also be copied together, then we will be able to empty a bit of compatibility.

The code is as follows:
Copy Code code as follows:

var file = $ ("#file")
File.after (File.clone (). Val (""));
File.remove ();

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: info-contact@alibabacloud.com 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.