Bootstrapvalidation无效

我正在尝试使用bootstrap进行validation。 我在这里试过解决方案,但它没有用。

我添加了正确的js文件,请参阅小提琴链接 。 请帮忙知道问题所在。

这是一个有效的工作: http : //jsfiddle.net/P28nR/1/

缺少或不正确的事情是:

  • 你没有包含jquery
  • 你包含了错误的jquery bootstrap插件。 可以在以下链接中找到正确的文件:

//cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.4.5/css/bootstrapvalidator.min.css //cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.4.5/js/bootstrapvalidator .min.js

  • 您没有添加javascript来配置和运行validation器插件

     $(document).ready(function() { $('#tryitForm').bootstrapValidator({ feedbackIcons: { valid: 'glyphicon glyphicon-ok', invalid: 'glyphicon glyphicon-remove', validating: 'glyphicon glyphicon-refresh' }, fields: { firstName: { validators: { notEmpty: { message: 'The first name is required and cannot be empty' } } }, lastName: { validators: { notEmpty: { message: 'The last name is required and cannot be empty' } } }, email: { validators: { notEmpty: { message: 'The email address is required' }, emailAddress: { message: 'The input is not a valid email address' } } }, gender: { validators: { notEmpty: { message: 'The gender is required' } } } }, submitHandler: function(validator, form, submitButton) { var fullName = [validator.getFieldElements('firstName').val(), validator.getFieldElements('lastName').val()].join(' '); alert('Hello ' + fullName); } }); }); 
  1. 你没有包含jQuery。 Bootstrap插件需要jQuery。

  2. 你有两次jqBootstrapValidation:首先是人类可读的版本,然后是缩小版本。 仅包括缩小版本。

  3. 加载外部JS库时,顺序很重要。 首先加载jQuery,然后加载Bootstrap脚本,然后加载任何其他插件。 JS从上到下执行,因此必须在脚本之前加载依赖项。