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

女生的网名这么多〃 提交于 2019-12-06 02:23:59

问题


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?


回答1:


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



回答2:


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



回答3:


$('#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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!