Home > Web Front-end > JS Tutorial > The File field in IE cannot be cleared. Use jQuery to reset the File field_jquery

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

WBOY
Release: 2016-05-16 16:51:14
Original
1222 people have browsed it

Sometimes when uploading files, you will encounter a situation where you need to reset the entire form, but here comes the problem. Other browsers don't have any problems. Just reset the form directly or trigger the click event of the button with type reset. OK, but IE is weird. The File field in IE cannot be cleared. Maybe you see that there is no value anymore, but you can print it out and see:

Copy code The code is as follows:

var fileVal = $('input[type="file"]').val();
alert(fileVal);

The information printed out is still the information of the file selected before reset. How to solve this problem? After checking a lot of information, I found that the following method can be used to solve the problem under IE
Copy code The code is as follows:

$('input[type="file"]') .attr('value','');
//or
$('input[type="file"]').val('');

Of course Don't forget to reset the form.
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