jquery validate 验证插件 解决多个相同的Name 只验证第一个的方案
方案一:如果 项目里不是只是个别页面 有多个name 验证,
那么利用 prototype 来写,把这段代码加在你所要使用多个name的页面 的js初始化里 即可
if ($.validator) {
$.validator.prototype.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;
});
}
}
方案二:修改源文件 这样做 就是所有的页面都可以验证多个name
利用 ctrl+F 查找 this.name in rulesCache 找到 源码 (不是压缩过的 min.js)。把这行if判断注释即可。
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;
});
},
如果是压缩js min.js :
查找 这段 (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插件进行表单里控件的验证
jsp中具体实现的代码: <%@ page language="java" contentType="text/html; charset=UTF-8" ...
- jQuery Validate 表单验证插件----通过name属性来关联字段来验证,改变默认的提示信息,将校验规则写到 js 代码中
一.下载依赖包 网盘下载:https://yunpan.cn/cryvgGGAQ3DSW 访问密码 f224 二. 添加一个另外一个插件jquery.validate.messages_cn.js. ...
- jquery.validate.js插件的使用方法
近期做项目.须要用到 jQuery.validate.js插件,于是记录一下工作中的一些经验,以便日后学习. [样例例如以下] 1.前台页面 <form id="form1" ...
- 【转载】jquery validate验证插件,在ajax提交方式下的验证
正常的表单都是使用submit按钮来提交,jquery validate插件可以方便的做表单验证. 做一个发送短信的功能,向目标表插入多条记录,界面采用ajax来提交表单,等待效果直接用ext的遮罩 ...
- 用jQuery Validate+layer插件实现好看的表单提交效果
作为初学者,以前做表单验证都是自己写的,目的是让自己更好的了解代码,加深自己对javascript的理解,但是其实在很久都知道有一个很好用的表单验证插件:jQuery Validate.js,一直都没 ...
- jquery.validate 中文乱码解决方法
第一种.就是所说的引用jquery.validate.messages_cn.js 下载地址:http://files.cnblogs.com/files/pin ...
- jquery.validate.js插件使用
jQuery验证控件jquery.validate.js使用说明+中文API 官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-valid ...
- 表单验证代码实例:jquery.validate.js表单验证插件
jquery.validate.js是JQuery旗下的一个验证插件,借助JQuery的优势,我们可以迅速验证一些常见的输入,并且可以自己扩充自己的验证方法.使用前请先下载必要的JQuery插件:jq ...
- 表单验证神器——jquery.validate插件
jquery.validate.js插件应用举例,ajax方式提交数据. html代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tr ...
随机推荐
- vscode搭建python环境
这两天刚下了一个pycharm,结果使用之后将vscode给崩了,重装的时候有些步骤也记不清,走了一些弯路,做个总结来记录一下(本人觉得vscode比pycharm好用一点). Python下载安装 ...
- vmare下克隆一台linux
第一步:点击"克隆"按钮,注意,克隆之前选择的机器需要关机 第二步:接下来需要改一下新机器的mac地址,选中新机器,右键"设置"-->"网络适配 ...
- SpringBoot配置Https
HTTPS (全称:Hyper Text Transfer Protocol over SecureSocket Layer),是以安全为目标的 HTTP 通道,在HTTP的基础上通过传输加密和身份认 ...
- EasyUI学后总结第一集
1,创建Easyui组件-使用html还是使用js方式? 如果在创建Easyui组件的时候,组件再被更改,那么属于静态组件,对于静态组件不要使用js方式创建--会增加js代码量. 如果创建的Easyu ...
- 【剑指offer】27. 二叉树的镜像
剑指 Offer 27. 二叉树的镜像 知识点:二叉树:递归:栈 题目描述 请完成一个函数,输入一个二叉树,该函数输出它的镜像. 示例 输入:root = [4,2,7,1,3,6,9] 输出:[4, ...
- windows系统pycharm终端更改为git bash
引自:https://blog.csdn.net/u011519550/article/details/89855122 设置路径:file--setting--tools--terminal--ap ...
- intouch制作历史趋势公用弹窗
在先前项目中,历史趋势都是作为一个总体的画面,然后添加下拉菜单选择来配合使用.在新项目中,业主要求在相应的仪表上直接添加历史趋势,这就需要利用公用弹窗来制作历史趋势了. 1.窗体建立 窗体建立是比较简 ...
- bootstrap table记录一下
$(function() { // 刷新 talbe function refresh() { $("#table").bootstrapTable('refresh'); } $ ...
- tp3 联表查询
联表查询D("column") ->field("{$DbPrefix}column.pid,{$DbPrefix}news.*") ->where ...
- 论文笔记:(NIPS2017)PointNet++: Deep Hierarchical Feature Learning on Point Sets in a Metric Space
目录 一. 存在的问题 1.提取局部特征的能力 2.点云密度不均问题 二.解决方案 1.改进特征提取方法: (1)采样层(sampling) (2)分组层(grouping) (3)特征提取层(fea ...