没什么好讲的,上代码:
(function ($) { var defaultOptions = { validClass: 'has-success', errorClass: 'has-error', highlight: function (element, errorClass, validClass) { $(element).closest(".form-group") .removeClass(validClass) .addClass(errorClass); }, unhighlight: function (element, errorClass, validClass) { $(element).closest(".form-group") .removeClass(errorClass) .addClass(validClass); } }; $.validator.setDefaults(defaultOptions); if ($.validator.unobtrusive) { $.validator.unobtrusive.options = { errorClass: defaultOptions.errorClass, validClass: defaultOptions.validClass }; } })(jQuery);
jQuery Validation Unobtrusive Native
https://johnnyreilly.github.io/jQuery.Validation.Unobtrusive.Native/Home/GettingStarted.html