2017-07-25 61 views
0

我有一個窗體,並在JS中進行驗證,當用戶發送不同於.doc/.docx的窗體不發送。 (簡歷上傳)。 但我想這得更快。立即得到錯誤選擇文件時,不是當按鈕被提交。 (在Windows窗口中)。JS文件上傳驗證,但即時在Windows窗口

怎麼辦?它的標準形式:

<div class="form-group"> 
             <label>Your CV</label> 
             <input required type="file" accept="application/msword" class="form-control" name="cv" id="cv" aria-describedby="name" placeholder="Select a CV file"/> 
            </div> 
+0

無法在Windows 10上覆制。瀏覽文件時,它會自動應用「Word 2003 Document」過濾器(隱藏未驗證的文件)。 – yuriy636

回答

0

我剛剛得到了答案。這裏的代碼(isDoc是我自己的功能):

function onChange(event) { 
     var file = $('#file_cv')[0].files[0]; 
     if (!isDoc(file.name)) { 
      alert("Please, choose .doc or .docx type."); 
      document.getElementById("file_cv").value=""; 
} 
} 

現在,無法發送表單而不發送正確的文件。