jquery validate 如何校验多个相同name
在表单页中有如下代码
<form>
<input name="zhai"/><!-- 三个相同name的input -->
<input name="zhai"/>
<input name="zhai"/>
</form>
问题:jquery validate在对多个相同name校验时,只校验第一个input框。
解决方案一:在表单页对应的js中加入如下代码 只有当前页可以解决对多个name校验
if ($.validator) {
$.validator.prototype.elements = function () {
var validator = this,
rulesCache = {};
return $(this.currentForm)
.find("input, select, textarea")
.not(":submit, :reset, :image, [disabled]")
.not(this.settings.ignore)
.filter(function () {
if (!this.name && validator.settings.debug && window.console) {
console.error("%o has no name assigned", this);
}
rulesCache[this.name] = true;
return true;
});
}
}
解决方案二:修改源文件 所有的页面都可以验证多个name
方式1:修改jquery.validate.js文件
用 ctrl+F 查找 this.name in rulesCache 注释掉如下代码。
elements: function() {
var validator = this,
rulesCache = {};
// select all valid inputs inside the form (no submit or reset buttons)
return $(this.currentForm)
.find("input, select, textarea")
.not(":submit, :reset, :image, [disabled]")
.not( this.settings.ignore )
.filter(function() {
if ( !this.name && validator.settings.debug && window.console ) {
console.error( "%o has no name assigned", this);
}
// 注释掉这里
// select only the first element for each name, and only those with rules specified
//if ( this.name in rulesCache || !validator.objectLength($(this).rules()) ) {
// return false;
//}
rulesCache[this.name] = true;
return true;
});
},
方式2:修改jquery.validate.min.js文件用 ctrl+F 查找(c[this.name]=!0,!0)})
return !this.name && b.settings.debug && window.console && console.error("%o has no name assigned", this),
//this.name in c || !b.objectLength(a(this).rules()) ? !1 : (c[this.name] = !0, !0)//注释这行
c[this.name] = !0, !0 //添加这行
解决方案一验证可用,其他方案暂未校验。
本文来源
jquery validate 如何校验多个相同name的更多相关文章
- jquery.validate.js校验select2解决方案,Jquery插件select2校验解决方案
jquery.validate.js校验select2解决方案 Jquery插件select2校验解决方案 >>>>>>>>>>>&g ...
- 通过jquery.validate.js校验表单字段是否合法
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- jquery validate 自定义校验方法
1.引入JS jquery.min.js jquery.validate.min.js messages_zh.min.js 2.添加验证方法,第一个参数为验证方法的名称,第二个参数为验证方法. $. ...
- bootstrap+jQuery.validate表单校验
谈谈表单校验 这大概是一种惯例,学习前台后台最开始接触的业务都是用户注册和登录.现在社会坚持以人为本的理念,在网站开发过程同样如此.User是我们面对较多的对象,也是较核心的对象.最开始的用户注册和登 ...
- jQuery.validate表单校验+bootstrap
谈谈表单校验 这大概是一种惯例,学习前台后台最开始接触的业务都是用户注册和登录.现在社会坚持以人为本的理念,在网站开发过程同样如此.User是我们面对较多的对象,也是较核心的对象.最开始的用户注册和登 ...
- jquery.validate.js默认配置,jquery.validate.js自定义提示信息
jquery.validate.js默认配置,jquery.validate.js自定义提示信息 配置jQuery.validator默认的处理方法 >>>>>>& ...
- 使用jquery.validate.js实现boostrap3的校验和验证
使用jquery.validate.js实现boostrap3的校验和验证 boostrap3验证框架 jquery.validate.js校验表单 >>>>>>& ...
- bootstrap+jQuery.validate
bootstrap+jQuery.validate表单校验 谈谈表单校验 这大概是一种惯例,学习前台后台最开始接触的业务都是用户注册和登录.现在社会坚持以人为本的理念,在网站开发过程同样如此.Us ...
- Bootstrap 与 Jquery validate 结合使用——多个规则实现
进行开发的时候,遇到了需要有多个规则来校验,如新用户过来一套校验规则,老用户过来又是一套规则,这时候就要需要定义多套校验规则. 首先要熟悉Bootstrap和Jquery validate的使用,详情 ...
随机推荐
- 三分钟掌握共享内存 & Actor并发模型
吃点好的,很有必要.今天介绍常见的两种并发模型: 共享内存&Actor 共享内存 面向对象编程中,万物都是对象,数据+行为=对象: 多核时代,可并行多个线程,但是受限于资源对象,线程之间存在对 ...
- Guava Cache使用的三种姿势
姿势一 使用expiredAferWriter 优点 简单 粗暴 缺点 同步阻塞问题:如果多个线程同时请求同一个过期的key,只有一个线程能够获得去加载缓存的锁,但是其他未获取加载缓存锁的线程也会阻塞 ...
- Unittest方法 -- 测试套件
TestSuite 测试固件 一. import unittestclass F6(unittest.TestCase): def setUp(self): pass def tearDown(sel ...
- 8Java设计模式(持续更新)
1.单例模式(Singleton pattern): 单例模式的实现方式是,一个类能返回对象的一个引用(永远是同一个)和一个获得该唯一实例的方法(必须是静态方法). 饿汉式: public class ...
- synchronized锁机制(六)
前言 1.理解同步关键词synchronized 2.同步方法与同步代码块的区别 3.理解锁的对象this 脏读 一个常见的概念.在多线程中,难免会出现在多个线程中对同一个对象的实例变量进行并发访问的 ...
- odoo12里定时任务
以odoo12为例: 1. 定义定时任务属性 <record id="ir_cron_submit_auto_action" model="ir.cron" ...
- cytoscape-d3-force api
{ animate:true,//是否在布局运行时显示布局:特殊的"结束"值使布局具有离散布局的动画效果 maxIterations:0,//布局退出前的最大迭代次数 maxSim ...
- Spring Data Commons 远程命令执行漏洞(CVE-2018-1273)
影响版本 Spring Framework 5.0 to 5.0.4 Spring Framework 4.3 to 4.3.14 poc https://github.com/zhzyker/exp ...
- charles抓取https设置
第一步:打开charles,查看电脑ip,手机设置代理(需要手机和电脑在同一网络) 手机下载证书不要用自带的下,会失败 1.查看电脑ip 2.手机设置代理,修改网络,保存 3.手机访问"看图 ...
- Kubernetes安装报错总结
1.kubeadm init初使化报错 [root@k8s01 ~]# kubeadm init --kubernetes-version=v1.13.3 --pod-network-cidr=1 ...