bootstrap的表单验证formValidation有返回值吗?如何设置返回值呢?最好能举个例子.谢谢!
$('#mailform').validate(
{
submitHandler : function(form) {
//ajax提交注册信息,并且返回注册结果
//使用ajax的post方法提交注册信息
$.post('/video-web/user/forgetpwd.action', $(
'#mailform').serialize(), function(result) {
if (result == "true") {
location.href="/video-web/user/reset_pwd.action";
} else {
alert("验证码错误");
}
}, 'text');
},
rules : {//写校验规则的
email : {
required : true,
email:true,
minlength : 3
},
captcha : {
required : true
}
},
messages : {//写提示信息的
email : "邮箱是必须填写的",
captcha : '验证码是必须填写的'
}
});
submit提交
$('#defaultForm').formValidation({
message: '此值无效', icon: { valid: 'glyphicon glyphicon-ok', invalid: 'glyphicon glyphicon-remove', validating: 'glyphicon glyphicon-refresh' }, locale: 'zh_CN', fields:{
boxId:{
verbose: false,//代表验证按顺序验证。验证成功才会下一个(验证成功才会发最后一个remote远程验证)
validators: {
notEmpty: {
message: '这是必填字段'
},
digits: {
message: '值不是数字'
},
stringLength: {
min: 16,
message:'必须为16个数字'
},
remote: {
type: 'POST',
url: '/box/unique',
message: '此设备号已存在',
delay: 2000
}
}
},
onSuccess:function(){
//点击提交表单。表单所有都验证成功
}
});
var subform;
//打开表单时初始化验证信息
var initSubmitValidata = function() {
subform = $('#addForm');
subform.bootstrapValidator({
message: '输入值不合法',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
type: {
validators: {
notEmpty: {
message: '请选择文件类型'
}
}
},
description: {
validators: {
stringLength: {
min: 1,
max: 50,
message: '描述信息长度应在1到50个字符之间'
}
}
}
}
});
}
//提交button绑定的事件(注意:提交按钮类型为button,不是submit)
var submitForm=function(){
//进行表单验证
var bv = subform.data('bootstrapValidator');
bv.validate();
if (bv.isValid()) {
//ajax提交信息到后台
}
}
这是这个验证插件中提供的方法,至于jQuery.data()方法解释如下:
$("#btn1").click(function(){
$("div").data("greeting", "Hello World");
});
$("#btn2").click(function(){
alert($("div").data("greeting"));
});
也就是说,这个插件帮我们给bootstrapValidator这个对象中封装了验证信息,现在我们提交的时候把这个验证信息取出来就行了。