Bootstrap表单validation无效

我正在尝试使用bootstrapvalidation器validation用户名和密码字段我已将css和js包含在bootstrapvalidation器中。 要validation的表单ID是#login

代码如下

         $(document).ready(function() { $('#login').bootstrapValidator({ feedbackIcons: { valid: 'glyphicon glyphicon-ok', invalid: 'glyphicon glyphicon-remove', validating: 'glyphicon glyphicon-refresh' }, fields: { userName: { validators: { notEmpty: { message: 'User Name required' } } }, password: { validators: { notEmpty: { message: 'TPassword required' } } } } }); });   

如何解决这个问题。

小提琴演示jsfiddle.net/xrcwrn/3bthv

这是一个工作小提琴

问题是你的小提琴包含的js代码包含语法错误。 当你的javascript没有按预期工作时,控制台应该是你检查的第一件事。 我在下面的代码中评论了我为使小提琴工作所做的改变。 (看起来你问题中的代码很好)

 $(document).ready(function() { $('#login').bootstrapValidator({ feedbackIcons: { valid: 'glyphicon glyphicon-ok', invalid: 'glyphicon glyphicon-remove', validating: 'glyphicon glyphicon-refresh' }, fields: { userName: { validators: { notEmpty: { message: 'The first name is required and cannot be empty' } } }, password: { validators: { notEmpty: { message: 'The last name is required and cannot be empty' } } } /* <-- removed unneeded comma */ } /* <-- added closing brace */ }); });