Bootstrapvalidator校验、校验清除重置的实现代码(推荐)
作者:zhangtongzct 发布时间:2024-04-10 13:52:57
标签:bootstrap,validator,校验,重置
1.引入css与js
bootstrapValidator.min.css
bootstrapValidator.min.js
2.html中的modal代码
<div class="modal fade" id="editModal" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content" >
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
<h4 class="modal-title" id="editModalLabel"></h4>
</div>
<div class="modal-body">
<!-- form start -->
<form class="form-horizontal" id="saveadmin_form"
name="form-horizontal">
<input type="hidden" id="adminid" />
<div class="box-body">
<dl class="dl-horizontal">
<div class="form-group">
<div class="col-sm-10">
<dt>管理员名</dt>
<dd>
<lable id="edit_show_adminname"></lable>
<input type="text" class="form-control" id="edit_adminName"
name="edit_adminName" data-bv-notempty="true"
name="edit_adminName">
</dd>
</div>
</div>
<div class="form-group" id="div_password">
<div class="col-sm-10">
<dt>密码</dt>
<dd>
<input type="text" class="form-control" name="edit_passwd"
id="edit_passwd">
</dd>
</div>
</div>
<div class="form-group" id="div_password1">
<div class="col-sm-10">
<dt>确认密码</dt>
<dd>
<input type="text" class="form-control" name="edit_passwd1"
id="edit_passwd1">
</dd>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<dt>显示名</dt>
<dd>
<input type="text" name="edit_displayName"
class="form-control" id="edit_displayName">
</dd>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<dt>邮箱</dt>
<dd>
<input type="text" data-bv-notempty="true" name="edit_Mail"
class="form-control" id="edit_Mail">
</dd>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<dt>备注</dt>
<dd>
<textarea class="form-control" name="edit_desc" rows="3"
id="edit_desc"></textarea>
</dd>
</div>
</div>
</dl>
</div>
<!-- /.box-body -->
<div class="modal-footer">
<!-- <button type="button" onclick="saveAdmin()" class="btn btn-default">保存</button> -->
<button onclick="saveAdmin()" type="button" class="btn btn-success">
<i class="fa fa-check"></i> 保存
</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">
<i class="fa fa-times"></i> 关闭
</button>
</div>
</form>
</div>
</div>
</div>
</div>
3.js代码
//保存
function saveAdmin(){
//开启验证
$('#saveadmin_form').data('bootstrapValidator').validate();
if(!$('#saveadmin_form').data('bootstrapValidator').isValid()){
return ;
}
//表单提交
$.ajax({
type: "POST",
dataType : 'json',
url: "<%=request.getContextPath()%>/user/saveUser.html?ma="+Math.random(),
data: {
"type" :"0",
"id":$("#adminid").val(),
"account":$("#edit_adminName").val(),
"display_name":$("#edit_displayName").val(),
"password":$("#edit_passwd").val(),
"mail":$("#edit_Mail").val(),
"role":$("#edit_role").val(),
"desc":$("#edit_desc").val()
},
success :function(json) {
json = eval("("+json+")");
$("#editModal").modal("hide");
$("#dialog_content").html(json.message);
$("#dialog_button_queren").hide();
$("#dialog_modal").modal("show");
t.ajax.reload( null, true );
}
});
}
//初始化表单验证
$(document).ready(function() {
formValidator();
});
/*********************************校验重置重点在这里 当modal隐藏时销毁验证再重新加载验证****************************************/
//Modal验证销毁重构
$('#editModal').on('hidden.bs.modal', function() {
$("#saveadmin_form").data('bootstrapValidator').destroy();
$('#saveadmin_form').data('bootstrapValidator', null);
formValidator();
});
//form验证规则
function formValidator(){
$('#saveadmin_form').bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
//管理员名
edit_adminName: {
message: '管理员名验证失败',
validators: {
notEmpty: {
message: '管理员名不能为空'
},
stringLength: {
min: 5,
max: 64,
message: '管理员名长度必须在6到64位之间'
}
}
},
//密码
edit_passwd: {
message: '密码验证失败',
validators: {
notEmpty: {
message: '密码不能为空'
},
stringLength: {
min: 5,
max: 64,
message: '密码长度在5到64之间'
}/* ,
identical: {
field: 'edit_passwd1',
message: '两次密码不相同'
} */
}
},
//密码确认
edit_passwd1: {
message: '密码确认验证失败',
validators: {
notEmpty: {
message: '密码确认不能为空'
},
identical: {
field: 'edit_passwd',
message: '两次密码不相同'
}
}
},
//显示名
edit_displayName: {
message: '用户名验证失败',
validators: {
notEmpty: {
message: '显示名不能为空'
},
stringLength: {
min: 5,
max: 128,
message: '显示名长度必须在6到18位之间'
}
}
},
//邮箱
edit_Mail: {
validators: {
notEmpty: {
message: '邮箱不能为空'
},
emailAddress: {
message: '邮箱格式正确'
},
stringLength: {
max:256,
message: '邮箱长度必须小于256'
}
}
},
//备注
edit_desc: {
message: '备注验证失败',
validators: {
stringLength: {
max: 256,
message: '备注长度长度必须小于256'
}
}
},
}
});
}
以上所述是小编给大家介绍的Bootstrapvalidator校验、校验清除重置的实现代码(推荐)网站的支持!
来源:http://www.cnblogs.com/zhangtongzct/p/5728592.html


猜你喜欢
- 下面十条内容的标题原本是《10 Lessons for Young Designers》,是John C. Jay给年青设计师们的十条经验教
- 阅读目录一般而言,当我们需要某些功能的模块时(无论是内置模块或自定义功能的模块),可以通过import module 或者 from * i
- 来一个简单的例子,看Python如何操作数据库,相比Java的JDBC来说,确实非常简单,省去了很多复杂的重复工作,只关心数据的获取与操作。
- 一、特效预览处理前处理后细节放大后二、程序原理将图片所在的 256 的灰度映射到相应的字符上面也就是 RGB 值转成相应的字符然后再将字符其
- char(n)是定长格式,格式为char(n)的字段固定占用n个字符宽度,如果实际存放的数据长度超过n将被截取多出部分,如果长度小于n就用空
- 1.编写python flask代码,简单写一个加法的接口,命名为sum.pyimport jsonfrom flask import Fl
- 为方便维护和实现开放性,我把调查的好几个主题都放到同一个数据库的同一个表名当中去了但问题是在查询其中一个调查主题时,往往还会显示不相关主题的
- 本文实例讲述了python实现通过代理服务器访问远程url的方法。分享给大家供大家参考。具体如下:import urllibproxies
- 简述一开始觉得这个很有趣,然后就想来做一个来玩一下使用语言: Python3使用工具:opencv视频监控 + socket数据传输技术程序
- 如下所示:s=subprocess.Popen("ping baidu.com -t",bufsize=0,stdout
- 新手,看到很多网页上有显示/隐藏的菜单,可以显示隐藏层的同时控制FLASH的播放与停止。找了好久都找不到这个功能。。。还望高人指点当点击时就
- Python的3.0版本,常被称为Python 3000,或简称Py3k。相对于Python的早期版本,这是一个较大的升级。为了不带入过多的
- 动态渲染就是有一个异步的数据,大概长这样:{ "inline": true, "labelPosition&q
- 如何制作一个弹出式的调查窗口?执行下面这段ASP代码: <% &n
- 在cmd下运行go程序或者是GOLAND的Terminal下运行go程序会出现中文乱码的情况。go run ttypemain.go����
- 什么是错误页面?是指链接指向的网页现在失效了,原因可能是用户输错了地址,也可能是网站结构调整,内容删除,或者地址变更都有可能出现这种情况。那
- 对于一个多元函数 用牛顿法求其极小值的迭代格式为其中 为函数 的梯度向量, 为函数 的Hesse(Hessian)矩阵。上述牛顿法
- 本文参加新星计划人工智能(Pytorch)赛道:https://bbs.csdn.net/topics/613989052一、强大的 hub
- 效果:myvcode.class.php:封装创建验证码的类<?php/** file:myvcode.class.php* 验证码类
- 本文实例讲述了Python自动扫雷实现方法。分享给大家供大家参考。具体如下:#pyWinmineCrack.py# coding: utf-