获取焦点 判断Ip

<pre class="javascript" name="code">addIp.js:
 var inputArray = $("#tBody tr td input");
	inputArray.each(function(i,value){
		$(this).keyup(function(e){
			var key =  e.which;
			IpFocus($(this),key);
		});
	});
 

 
 function IpFocus(obj,key){
	//先判断是否大于255     再让其推进后一个焦点
	if(key==110||key==39){
		if(obj.attr("name")=="beginIp4"){
			$("#endIp1").focus();
		}else{
			obj.next().focus();
		}
	}else if(key==37){
		if(obj.attr("name")=="endIp1"){
			$("#beginIp4").focus();
		}else{
			obj.prev().focus();
		}
	}else if(obj.val().length==3){
		if(parseInt(obj.val())>255||parseInt(obj.val())<1){
			art.dialog.alert(obj.val()+"不是一个有效数字,请制定一个介于1和255之间的数值");
			obj.focus();
			return;
		}else{
			if(obj.attr("name")=="beginIp4"){
				$("#endIp1").focus();
			}
			obj.next().focus();
		}
	}
}
 
function addIp(){
	var re =  /^([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])$/;  
	//拼接字符串
	var inputArray = $("#tBody tr td input");
	var input1Array = $("#div1 input");
	var input2Array = $("#div2 input");
	var beginIp = "";
	var endIp = "";
	var isNullBeginIp="";
	var isNullEndIp="";
	
	input1Array.each(function(i,value){
		if(i!=3){
			beginIp+=$.trim($(this).val())+".";
		}else{
			beginIp+=$.trim($(this).val());
		}
		isNullBeginIp+=$.trim($(this).val());
		if(isNullBeginIp!=""&&$.trim($(this).val())==""){
			art.dialog.alert("起始Ip格式不正确");
			return;
		}
	});
	input2Array.each(function(i,value){
		if(i!=3){
			endIp+=$.trim($(this).val())+".";
		}else{
			endIp+=$.trim($(this).val());
		}
		isNullEndIp+=$.trim($(this).val());
		if(isNullEndIp!=""&&$.trim($(this).val())==""){
			art.dialog.alert("截止IP格式不正确");
			return;
		}
	});
	if(isNullBeginIp==""){
		art.dialog.alert("起始Ip不能为空!");
		return;
	}
	if(isNullEndIp==""){
		art.dialog.alert("截止IP不能为空!");
		return;
	}
	if(!re.test(beginIp)){
		art.dialog.alert("起始Ip格式不正确");
		return false;
	}
	if(!re.test(endIp)){
		art.dialog.alert("截止IP格式不正确");
		return false;
	}
	//插入Ip
	if(isIpSection(beginIp,endIp)=="notEqual"){
		art.dialog.alert("起始Ip与截止IP不在同一段Ip范围内");
		return;
	}else if(isIpSection(beginIp,endIp)=="Error"){
		art.dialog.alert("截止IP不能小于起始Ip");
		return;
	}
	if(parseInt(beginIp4[3])>parseInt(endIp4[3])){
		art.dialog.alert("起始Ip与截止IP范围不正确");
	}
	
	var url = basePath+"attendance/addIp.action";
	var paramData = {
			"beginIp":beginIp,
			"endIp":endIp
	};
	$.ajax({
		url:url,
		type:"post",
		data:paramData,
		dataType:"text",
		success:function(data){
			if($.trim(data)==""){
				art.dialog.alert("添加成功",function(){
					art.dialog.close("addIp");
				});
			}else{
				art.dialog.alert("添加失败,请稍后重试!");
			}
		}
	});
}
/**
 * 判断两者是否在同一IP段内
 * @param beginIp
 * @param endIp
 */
function isIpSection(beginIp,endIp){
	var beginIpArray = beginIp.split(".");
	var endIpArray = endIp.split(".");
	var ip1 = (beginIpArray[0]==endIpArray[0]);
	var ip2 = (beginIpArray[1]==endIpArray[1]);
	var ip3 = (beginIpArray[2]==endIpArray[2]);
	var ip4 = (parseInt(beginIpArray[3])<=parseInt(endIpArray[3]));
	if(ip1&&ip2&&ip3){
		if(!ip4){
			return "Error";
		}else{
			return "";
		}
	}else{
		return "notEqual";
	}
	
}
 
 
 
 
 
addIp.jsp
 
 
<pre class="javascript" name="code"><pre class="javascript" name="code"><%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<jsp:include page="../../common/taglibs.jsp" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>弹框-考勤设置</title>
<jsp:include page="../../common/flatHead.jsp"></jsp:include>
<link href="${ctx}flat/css/reset.css" rel="stylesheet" type="text/css" />
<link href="${ctx}flat/css/attendance.css" rel="stylesheet" type="text/css" />
<link href="${ctx}flat/plugins/form/skins/form_default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${ctx}js/common/validate_form.js"></script>
<script type="text/javascript" src="${ctx}js/logined/js_lang_cn.js"></script>
<script type="text/javascript" src="${ctx}js/common/showError.js"></script>
<script type="text/javascript" src="${ctx}js/logined/attendance/addIp.js"></script>
</head>
<body class="formbg">
<div class="elasticFrame formPage">
    <table width="100%" cellspacing="0" cellpadding="0" border="0" class="inputTable">
      <tbody id="tBody">
        <tr>
          <th>IP段:</th>
          <td><div class="inputIP" id="div1"><input name="beginIp1" maxlength="3" οnkeyup="this.value=this.value.replace(/[^0-9]/g,'')" class="ipClass" id="beginIp1" type="text" />.<input name="beginIp2" id="beginIp2" maxlength="3" οnkeyup="this.value=this.value.replace(/[^0-9]/g,'')" class="ipClass" type="text" />.<input name="beginIp3" id="beginIp3" type="text" maxlength="3" οnkeyup="this.value=this.value.replace(/[^0-9]/g,'')" class="ipClass" />.<input name="beginIp4" id="beginIp4" type="text" maxlength="3" οnkeyup="this.value=this.value.replace(/[^0-9]/g,'')" class="ipClass" /></div>
            -
            <div class="inputIP" id="div2"><input name="endIp1" id="endIp1" type="text" maxlength="3" οnkeyup="this.value=this.value.replace(/[^0-9]/g,'')" class="ipClass"/>.<input name="endIp2" id="endIp2" type="text" maxlength="3" οnkeyup="this.value=this.value.replace(/[^0-9]/g,'')" class="ipClass"/>.<input name="endIp3" id="endIp3" type="text" maxlength="3" οnkeyup="this.value=this.value.replace(/[^0-9]/g,'')" class="ipClass"/>.<input name="endIp4" id="endIp4" type="text" maxlength="3" οnkeyup="this.value=this.value.replace(/[^0-9]/g,'')" class="ipClass"/></div></td>
        </tr>
      </tbody>
    </table>
    <input type="button" style="display:none;" id="a" class="formButton" value="保存" οnclick="addIp()" />
  </div>
</body>
</html>


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值