문제

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
   }
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top