The File field in IE cannot be cleared. Use jQuery to reset the File field.

Source: Internet
Author: User

Sometimes, when uploading files, you may encounter a situation where you need to reset the entire form, but the problem is that other browsers do not have any problems, it is okay to directly reset form or trigger the click Event of the button whose type is reset, but IE is amazing, and the File field in IE cannot be cleared. What you may see is that there is no value, but you can print it out and see it:
Copy codeThe Code is as follows:
Var fileVal = $ ('input [type = "file"] '). val ();
Alert (fileVal );

The printed file is the information of the file selected before reset. Should this be done? I checked a lot of information and found that the following methods can be used in IE to solve the problem:
Copy codeThe Code is as follows:
$ ('Input [type = "file"] '). attr ('value ','');
// Or
$ ('Input [type = "file"] '). val ('');

Of course, don't forget to reset the form.

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.