开发者

How to check an input type="file" has a file or not using jquery?

开发者 https://www.devze.com 2022-12-27 12:21 出处:网络
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?if (j

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?


if (jQuery('#File1').val()) { /* There are files */ }


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/>


$('#upload').bind('click', function(e){
   if( $('#File1').val() != ""){
       // file selected
   }
   else{
       // no file selected
   }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号