I have a file upload control <input id="File1" type="file" />
in my page... How to check an input type="file" has a file or not using jquery on click of a button upload
?
Quentin
if (jQuery('#File1').val()) { /* There are files */ }
Hardik Sondagar
You should use "required" instead of JQuery. By just one attribute it'll check input=file has file or not. Example:
<input type="file" required/>
jAndy
$('#upload').bind('click', function(e){
if( $('#File1').val() != ""){
// file selected
}
else{
// no file selected
}
});
来源:https://stackoverflow.com/questions/2642970/how-to-check-an-input-type-file-has-a-file-or-not-using-jquery