当前位置: 代码迷 >> Web前端 >> IP地址二事件
  详细解决方案

IP地址二事件

热度:144   发布时间:2012-10-30 16:13:36.0
IP地址2事件
var regex = /^[0-9]{0,3}$/; //三位数字
if(event.keyCode >= 37 && event.keyCode <= 40 && event.keyCode != 39)
return;
if(event.keyCode =={
var idName = v.id;
var num = parseInt(idName.substring(idName.length-1)) - 1;
if(v.value == ""){
    if(num == 0)return;
document.getElementById(ipid+"ip"+num).focus();
document.getElementById(ipid+"ip"+num).select();
}
}else{
var val = v.value;
var lastInput = val.substring(val.length-1);
var idName = v.id;
var num = parseInt(idName.substring(idName.length-1)) + 1;
if(event.keyCode == 39){
lastInput = '+';
}
switch(lastInput){
case '.':
val = val.substring(0,val.length-1);
if(!regex.test(val)){
val = val.substring(0,val.length-1);
if(!regex.test(val)){
val = val.substring(0,val.length-1);
}
}
v.value = val;
if(v.value != ""){
if(num == 5)return;
document.getElementById(ipid+"ip"+num).focus();
}
break;
case '+':
if(!regex.test(val)){
val = val.substring(0,val.length-1);
if(!regex.test(val)){
val = val.substring(0,val.length-1);
}
}
v.value = val;
if(v.value != ""){
if(num == 5)return;
document.getElementById(ipid+"ip"+num).focus();
}
break;
default:
if(!regex.test(val) || v.value > 255 || v.value < 0){
val = val.substring(0,val.length-1);
if(!regex.test(val) && val != ""){
val = val.substring(0,val.length-1);
}
if(!regex.test(val) && val != ""){
val = val.substring(0,val.length-1);
}
v.value = val;
return;
}
if(val.length>=3){
v.value = val.substring(0,3);
if(num == 5)return;
document.getElementById(ipid+"ip"+num).focus();
}
}
}
}
  相关解决方案