jQuery.validator 自定义验证消息
jQuery.validator.addMethod("ruletypeVali", function (value, element, params) { var customMsg = "请输入正确整数"; let result = true; let ruleType = $("#RuleType").val(); if (ruleType == "0") { if (value < params[0] || value > params[1]) { customMsg = "只能输入5-10之间的数值"; result = false; } } $.validator.messages.DaysToShipVali = customMsg; return this.optional(element) || result; }); $("#form-submit").validate({ rules: { RuleTypeCode: { required: true, digits: true, ruletypeVali:[5,10] }, }, messages: { RuleTypeCode: { required: "值不为空", digits: "必须输入整数", } }, onfocusout: function (e) { $(e).valid(); } });