jquery判斷 input type="file"上傳文件是否為空的方法:使用html上傳按鈕,代碼為【<button type="button" onclick="submitXML()">提交</button>】。
本教程操作環(huán)境:windows7系統(tǒng)、jquery3.2.1版本,DELL G3電腦,該方法適用于所有品牌電腦。
推薦:jquery視頻教程
jquery判斷 input type="file"上傳文件是否為空的方法:
要想獲取type="file"
的input內(nèi)容,用var file = $("id").val();
肯定是不行的,下面是代碼:
html上傳按鈕為:
<input type="file" id="reportXML" name="reportXML" title="輸入內(nèi)容" multiple="multiple"> <button type="button" onclick="submitXML()">提交</button>
js代碼:
function submitXML(){ var fileInput = $('#reportXML').get(0).files[0]; console.info(fileInput); if(fileInput){ $("#reportXMLform").submit(); }else{ alert("請選擇上傳文件!"); } }
相關(guān)免費(fèi)學(xué)習(xí)推薦:js視頻教程