Empty file File Upload domain jquery and JS method

Source: Internet
Author: User

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:

The code is as follows Copy Code

var file = $ ("#fileid");

File.after (File.clone (). Val (""));

File.remove ();

jquery also has a way

The code is as follows Copy Code

var afile = $ ("#" + picname);
Afile.replacewith (Afile.clone ());

JS clears the file domain information.

First you need to use a <div> or <span> tag to wrap up your file area for us to get it, like the following

The code is as follows Copy Code
<span id= "Pfile" ><input type= "file" name= "file" onkeydown= "return false" onpaste= "return false;" ></ Span></td>

Then execute the following JS before submitting the form

  code is as follows copy code

Document.getele Mentbyid ("Pfile"). InnerHTML = "<input type=" file "name=" file "onkeydown=" return false; "onpaste=" return false; " /> ";

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.