parsley jquery插件也这样做。
你可以在这里玩小提琴:
https://jsfiddle.net/djibe89/tu0ap111/
// Parsley plugin initialization with tweaks to style Parsley for Bootstrap 4
$("#my-form").parsley({
errorClass: 'is-invalid text-danger',
successClass: 'is-valid', // Comment this option if you don't want the field to become green when valid. Recommended in Google material design to prevent too many hints for user experience. Only report when a field is wrong.
errorsWrapper: '<span class="form-text text-danger"></span>',
errorTemplate: '<span></span>',
trigger: 'change'
}) /* If you want to validate fields right after page loading, just add this here : .validate()*/ ;
// Parsley full doc is avalailable here : https://github.com/guillaumepotier/Parsley.js/