jquery validate手动调用 校验

 jQuery().ready(function() {
            var validator = jQuery(".form1").validate({
                rules: {
                    docTypeId: "required",
                    "uploadFiles[0].file":"required"
                },
                messages: {
                    docTypeId: "请选择****",
                     "uploadFiles[0].file":"请选择文件"
                }
            });
            jQuery("#btn_submit").click(function() {
                var check = validator.form();
                if (check) {
                    jQuery(".form1").submit();
                }
            });
        });

 也可用如下方式:

 
function _submit(){
    var validator = jQuery(".form1").validate({
                rules: {
                    docTypeId: "required",
                    "uploadFiles[0].file":"required"
                },
                messages: {
                    docTypeId: "请选择 *****",
                     "uploadFiles[0].file":"请选择文件"
                }
            });
   if(validator.form()){
     jQuery(".form").submit();
   }
}

你可能感兴趣的:(jquery validate手动调用 校验)