这是我在表单中的一个字段的代码,对于unit_name。
$(document).ready(function() {
$('#alwaysEnableButtonForm').formValidation({
framework: 'bootstrap',
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
unit_name: {
validators: {
notEmpty: {
message: 'The task is required'
}
}
}
}
})
.on('err.field.fv', function(e, data) {
// $(e.target) --> The field element
// data.fv --> The FormValidation instance
// data.field --> The field name
// data.element --> The field element
data.fv.disableSubmitButtons(false);
})
.on('success.field.fv', function(e, data) {
// e, data parameters are the same as in err.field.fv event handler
// Despite that the field is valid, by default, the submit button will be disabled if all the following conditions meet
// - The submit button is clicked
// - The form is invalid
data.fv.disableSubmitButtons(false);
});
});
</script>
** 这是我的表单验证的JQUERY代码
有人能帮助我吗?
这是我的错误语法:
Uncaught TypeError: $(...).formValidation is not a function
at HTMLDocument.<anonymous> ((index):137)
at j (jquery.js:3099)
at Object.fireWith [as resolveWith] (jquery.js:3211)
at Function.ready (jquery.js:3417)
at HTMLDocument.I (jquery.js:3433)
这是我用来调用jquery验证的导入..
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
这是我用来显示验证信息的表单
<form name="#" method="POST" name="myForm" id="alwaysEnableButtonForm" >
<fieldset>
<legend>Insert unit:</legend>
<div class="form-group">
<label class="col-xs-3 control-label">Name unity: </label>
<div class="col-xs-5">
<input type="text" class="form-control" placeholder="name concept" name="unit_name" />
</div>
</div>
<input type="hidden" name="state" value="insert">
<div class="form-group">
<div class="col-xs-5 col-xs-offset-3">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</fieldset>
</form>
答案 0 :(得分:1)
您要在此处添加脚本:https://jqueryvalidation.org/
但是您自己的脚本正在尝试使用以下的api命令设置验证:http://formvalidation.io/,这是一个不同的商业jQuery验证库。