2017-07-25 23 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=""; 
} 
} 

现在,无法发送表单而不发送正确的文件。