jQuery 验证 - 即使指定了错误的文件类型,表单也会提交

jQuery Validation - Form submits even when wrong file-type is indicated

我为我的文件字段编写了以下规则,因为我希望只接受 PDF 文件的 Word 文档。

paperupload:{required: true, accept: "application/msword, application/pdf"}

当我使用上传的 JPG 文件进行测试时,表单提交时也没有验证其他字段。我在这里做错了什么吗?

$("#papersubmitform").validate(
    {
        submitHandler: function(form) {

                        $(form).submit();

        },

        messages: {
            //CHECK Correspondence Authors' Information
            contactTitle: "Please specify Correspondence Author's Title",
            contactFirstName: "Please specify Correspondence Author's First Name",
            contactLastName: "Please specify Correspondence Author's Last Name",
            contactEmail: "Please specify Correspondence Author's Email Address",
            contactUniList: "Please specify Correspondence Author's University",
            //paperTitle:"Please specify Paper Title",
            paperAbstract:"Please specify Paper Abstract"

        },

        rules:{
            //Rules for Correspondence Author's Information
            contactTitle: {required: true},
            contactFirstName: { required:true},
            contactLastName: { required:true},  
            contactEmail: {required:true, email: true},
            contactUniList:{ required:function(){
                if(checkuninotinlist){ return false; }
                    else { return true; }
                }
            },

            contactUniversityName:{ required: function(){
                    if(checkuninotinlist){ return true; }
                    else { return false; }
                    }
            },

            contactUniCountry:{ required: function(){
                    if(checkuninotinlist){ return true; }
                    else { return false; }
                    }
            },


            contactOrganisation: { required:function(){ 
                    if(checkorganisation){ return true; }
                    else { return false; }
                    }
            },

            contactOrgCountry: { required:function(){ 
                    if(checkorganisation){ return true; }
                    else { return false; }
                    }
            },

            mailinglist:{required:true},
            researchmethod:{required:true},

            //PAPER INFORMATION
            paperTitle:{required:true},
            paperAbstract:{required:true},
            paperupload:{required: true, accept: "application/msword, application/pdf"}

    }
 });            

HTML 在这里

<input type="file" name="paperupload" />

您必须包含 the additional-methods.js file 才能使用 accept 方法。

在包含 jQuery 验证插件后立即包含它。

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.validate.js"></script>
<script type="text/javascript" src="additional-methods.js"></script>