前端JS批量添加校验数据唯一性
<script type="text/javascript">
//维护删除数组中的某一项
Array.prototype.remove = function(val) {
var index = this.indexOf(val);
if (index > -1) {
this.splice(index, 1);
}
};
//array.remove('1');
//ajax从数据库模拟查出来的数据
var array=new Array("1","2","3","4","5","6");
var insertarr="";
var input=document.getElementsByTagName("input");
$(function(){
for(var i=0;i<input.length;i++){
//定位input
$("input:eq("+i+")").attr("index",i);
//改变的时候进行验证
$("input:eq("+i+")").on("change", function() {
var inputval=$(this).val();
//var inputindex=$(this).attr("index");
if($.inArray(inputval, array)=='-1'){//如果不包含在数组中,则返回 -1;
insertarr=inputval;
}else{
alert("请重新填写")
//$("input:eq("+inputindex+")").val("");
//$("input:eq("+inputindex+")").focus();
$(this).val("");
insertarr="";
}
if(insertarr!=null&&insertarr!=""){
array.push(insertarr);
}
//改变的同时删除数组中的值维护一个数组
if($("#jl").val()!=""&&insertarr!=$("#jl").val()){
array.remove($("#jl").val());
}
});
//获取焦点的时候进行验证
$("input:eq("+i+")").on("focus", function() {
var inputval=$(this).val();
$("#jl").val(inputval)
});
}
})
</script>
<center>
记录:
<input type="text" name="lishival" value="" id="jl">
<br/>
<input type="text" class="yz" value=""> <br/>
<input type="text" class="yz" value=""> <br/>
<input type="text" class="yz" value=""> <br/>
<input type="text" class="yz" value=""> <br/>
<input type="text" class="yz" value=""> <br/>
</center>
前端JS批量添加校验数据唯一性的更多相关文章
- ASP.NET MVC用存储过程批量添加修改数据
用Entity Framework 进行数据库交互,在代码里直接用lamda表达式和linq对数据库操作,中间为程序员省去了数据库访问的代码时间,程序员直接可以专注业务逻辑层的编写.但是对于比较复杂的 ...
- 使用ModelForm校验数据唯一性
在设计模型类的时候,将指定字段设置unique=true属性,可以保证该字段在数据库中的唯一性. 使用ModelForm可以将指定模型类快速生成表单元素.在提交数据后,使用is_valid()校验时, ...
- spring MVC 后端 接收 前端 批量添加的数据(简单示例)
第一种方式:(使用ajax的方式) 前端代码: <%@ page contentType="text/html;charset=UTF-8" language="j ...
- 使用Bootstrap + Vue.js实现 添加删除数据
界面首先需要引入bootstrap的css和bootstrap的js文件,还有vue.js和jQuery.js才可以看见效果. 这里提供bootstrap的在线文件给大家引用: <!-- 最新版 ...
- ArcEngine批量添加XY数据
使用ArcGIS Desktop “添加XY数据”或者“创建XY事件图层”工具 可以导入Excel坐标数据,生成临时图层并添加至ArcMap.ArcGlobe或者ArcScene中.在ArcEngin ...
- js动态添加table 数据tr td
成果库修改: 要求主题列表随成果类型改变而改变 网上查询资料后开工,在成果类型下拉框添加change()事件触发Dwr,查询主题集合——动态创建/编辑Table 概要代码 ...
- Js 动态添加的数据,监听事件监听不到
在开发中遇到这种问题,就是有些数据,比如按钮是动态添加进去的,结果添加事件监听无效,直接写死在页面上是可以的. 这就是很明显的加载先后顺序的问题了. 解决的方法: $(document).ready( ...
- yii 前端js动态添加验证规则
在使用 activeForm 生成表单及验证时,默认是按照 model 里的 rules 生成js验证,model 验证在加载完页面后生效,不可修改,如果需要扩展.动态验证,需要使用js来配合 直接上 ...
- mysql+php+pdo批量添加大数据
1.使用insert into插入 ini_set('max_execution_time','0');//限制超时时间,因为第一种时间较长,索性设为0不限制 $pdo = new PDO(" ...
随机推荐
- bzr: ERROR: No push location known or specified.
出现这种错误,要先uncommit,然后拉带最新版本,再commit最后push
- android 的AlertDialog对话框
private int selectedFruitIndex = 0; private void showMsg2() {// Dialog alertDialog = new AlertDial ...
- 10 Consensus and Profile
Problem A matrix is a rectangular table of values divided into rows and columns. An m×nm×n matrix ha ...
- 进入docker的4种方式
在使用Docker创建了容器之后,大家比较关心的就是如何进入该容器了,其实进入Docker容器有好几多种方式,这里我们就讲一下常用的几种进入Docker容器的方法. 进入Docker容器比较常见的几种 ...
- ubuntu12.04安装nox-classic
Setup Nox repo for ânox-dependenciesâ package $ cd /etc/apt/sources.list.d/ $ wget http://openfl ...
- alertView 上添加textField
- (void)showTextFieldUIAlertView { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@ ...
- leancloud js SDK 学习
测试页面 AV.initialize("id", "key"); var TestObject = AV.Object.extend("TestObj ...
- 原创:MVC 5 实例教程(MvcMovieStore 新概念版:mvc5.0,EF6.01) - 3、创建项目
说明:MvcMovieStore项目已经发布上线,想了解最新版本功能请登录 MVC 影视(MvcMovie.cn) 进行查阅.如需转载,请注明出处:http://www.cnblogs.com/Dod ...
- 安装、启动consul
1.下载 从consul官网https://www.consul.io/downloads.html下载 2.解压.配置 将下载的 consul_1.4.4_linux_amd64.zip 解压 t ...
- mysql 按照时间查询
这篇文章转载自http://blog.csdn.net/wangjuan_01/article/details/51726588 今天 select * from 表名 where to_days(时 ...