对jqueryValidate的使用心得 这个例子和bootstrap联合用的
来源:互联网 发布:商业组织顶级域名 编辑:程序博客网 时间:2024/06/01 07:45
首先要知道jqueryValidate一款提供表单验证的插件
下面是我开发的中的例子
commentForm 是form的id ,rules是验证规则,messages是返回的错误信息,messages可以省略,单最好根据自己的业务,去定义,如果直接是通过表单提交的,使用下面的方法就行,如果是通过ajax提交的,就要在ajax外面加一层判断
例如if($("#commentForm").valid()){
这里写提交的
var xxx=("#ddd").val();
$.ajax({
});
}
例如if($("#commentForm").valid()){
这里写提交的
var xxx=("#ddd").val();
$.ajax({
});
}
$("#commentForm").validate({ errorPlacement: function errorPlacement(error, element) { if(element.prop("name") == "color"){ element.parent().parent().before(error); }else{ element.before(error); } }, rules: { productBrand: { required: true, }, productNameNew: { required: true, }, productModel: { required: true, }, productBrandWidth: { required: true, }, name: { required: true, maxlength:20 }, salePrice: { required: true, range:[0,9999], maxlength:6 }, marketPrice:{ range:[0,9999], maxlength:6 }, salesPromotion:{ maxlength:20 }, gift:{ maxlength:85 } }, messages:{ productBrand: { required: "产品品牌必选", }, productNameNew: { required: "产品名称必选", }, productModel: { required: "产品型号必选", }, productBrandWidth: { required: "带宽必选", }, name: { required: "销售品名称不能为空", maxlength:"最大长度为20个字符" }, salePrice: { required: "销售价不能为空", range:"请输入9999以内的数字" , maxlength:"最大长度为6位数字" }, marketPrice:{ range:"请输入9999以内的数字", maxlength:"最大长度为6位数字" }, salesPromotion:{ maxlength:"最大长度为20个字符" }, gift:{ maxlength:"最大长度为85个字符" } } });需要引用的js<script type="text/javascript"src="jquery-3.1.0.min.js"></script>
<script type="text/javascript"src="jquery.pnotify.js"></script>
<script type="text/javascript"src="jquery.validate.min.js"></script>
<script type="text/javascript" src="messages_zh.min.js"></script>
jsp<div class="form-group"> <label for="name" class="control-label"><labe style="color:red;">*</labe>销售品名称</label> <input type="text" name="name" class="form-control" value="" id="name" placeholder="请输入销售品名称"></div>
0 0
- 对jqueryValidate的使用心得 这个例子和bootstrap联合用的
- bootstrap的datepicker、datetimepicker和jquery的datepicker使用心得
- bootstrap 基本例子,导航栏和container的使用
- 4JqueryValidate的异步校验
- bootstrap的datepicker控件使用心得
- bootstrap的datepicker控件使用心得
- bootstrap-datepicker日历控件的使用心得
- 初学者对bootstrap感觉,弹出框和进度条的使用
- jquery validate使用和扩展规则,jqueryvalidate
- Bootstrap Search Suggest 使用的例子
- MAG中关于数组和COMBO,LIST的联合使用例子(MAGList和MAGInputList)
- codesmith,nettiers与sql server联合使用的心得
- codesmith,nettiers与sql server联合使用的心得
- bootstrap的模态框例子
- 1.JqueryValidate的简单验证(js)
- 2.JqueryValidate的简单验证(表单内)
- 联合索引的经典例子
- Service和广播联合更新UI的例子
- hashmap原理及与hashtable区别
- EditText限制 只能输入0.00 -100保留两位小数
- java利用joup,imageio,base64来实现简历下载为html格式。
- DBCP和C3P0连接MySQL数据库
- CDN技术原理以及所用技术介绍
- 对jqueryValidate的使用心得 这个例子和bootstrap联合用的
- 数字格式化xx,xxx,xxx
- 关于ValueAnimator无作用
- FormData 的方法说明
- 看设计师大牛如何将用户体验与建站融会贯通
- 运行pythonp 提示:please select a valid interpreter
- 关于使用vue.js的模板渲染时出现一瞬间的设置的模板的解决方案
- Three.js中的光源
- ArcGIS API for JavaScript 4.x中的3D部分(1)