求解决!!!当输入的是2位的数字与输入的是3位数字时按小数点或者方上键 选择中后填写的效果一样!
<script type="text/javascript">var _value0="";
var _value1="";
var _value2="";
var _value3="";
function down_mask(obj,_value){
var form = document.forms[0];
var key1,nextip;
obj.value=obj.value.replace(/[^\d]/g,'')
key1=event.keyCode
var ipname = obj.name;
var iplength = ipname.length;
var realName = ipname.substr(0,iplength-1);
if (key1==190 || key1==110)//按.换输入框
{
nextip=parseInt(ipname.substr(iplength-1,1))+1;
nextip=nextip>=4?0:nextip;
//nextip=nextip<=-1?3:nextip;
// nextip=nextip-1;
// alert(nextip<=-1?3:nextip);
//form.'+realName+nextip+'.focus();
//form.'+realName+nextip+'.select();
// eval("form."+realName+nextip+".focus()");
eval("form."+realName+nextip+".select()");
eval("form."+realName+(nextip)).value=eval("form."+realName+(nextip)).value;
//form.'+realName+nextip+'.value = form.'+realName+nextip+'.value;
}else{
if( obj.value.length>=3 &&( (key1>=48 && key1<=57) || ( key1>=96 && key1<=105 ) ) )
{
nextip=parseInt(ipname.substr(iplength-1,1));
nextip=nextip>=4?0:nextip;
// nextip=nextip<=-1?3:nextip;
// nextip=nextip-1;
// eval("form."+realName+nextip+".focus()");
eval("form."+realName+nextip+".select()");
//form.'+realName+nextip+'.focus();
//form.'+realName+nextip+'.select();
}
}
}
function mask(obj){
var form = document.forms[0];
var key1,nextip;
obj.value=obj.value.replace(/[^\d]/g,'')
key1=event.keyCode
var ipname = obj.name;
var iplength = ipname.length;
var realName = ipname.substr(0,iplength-1);
if (key1==190 || key1==110)//按.换输入框
{
nextip=parseInt(ipname.substr(iplength-1,1));
nextip=nextip>=4?0:nextip;
// nextip=nextip<=-1?3:nextip;
//nextip=nextip-1;
// eval("form."+realName+nextip+".focus()");
eval("form."+realName+nextip+".select()");
// form.'+realName+nextip+'.focus();
//form.'+realName+nextip+'.select();
}
if ( key1==39)//光标右移一个框
{
nextip=parseInt(ipname.substr(iplength-1,1))+1;
nextip=nextip>=4?0:nextip;
// nextip=nextip<=-1?3:nextip;
// eval("form."+realName+nextip+".focus()");
eval("form."+realName+nextip+".select()");
}
if ( key1==37)//光标左移一个框
{
nextip=parseInt(ipname.substr(iplength-1,1))-1;
nextip=nextip>=4?0:nextip;
// nextip=nextip<=-1?3:nextip;
// eval("form."+realName+nextip+".focus()");
eval("form."+realName+nextip+".select()");
}
if( obj.value.length>=3 && ( (key1>=48 && key1<=57) || ( key1>=96 && key1<=105 ) ) )
{
nextip=parseInt(ipname.substr(iplength-1,1))+1;
nextip=nextip>=4?0:nextip;
// nextip=nextip<=-1?3:nextip;
// nextip=nextip-1;
// eval("form."+realName+nextip+".focus()");
eval("form."+realName+nextip+".select()");
// form.'+realName+nextip+'.focus();
// form.'+realName+nextip+'.select();
}
}
</script>
<BODY>
<form name="wearchip">
<input type="text" size=3 maxlength=3 name="wan_ipaddr_0" id="w0" onkeydown="down_mask(this,this.value)" onkeyup="mask(this)"/>.<input type="text" size=3 maxlength=3 name="wan_ipaddr_1" id="w1" onkeydown="down_mask(this,this.value)" onkeyup="mask(this)" />.<input type="text" size=3 maxlength=3 name="wan_ipaddr_2" onkeydown="down_mask(this,this.value)" onkeyup="mask(this)"/>.<input type="text" size=3 maxlength=3 name="wan_ipaddr_3" onkeydown="down_mask(this,this.value)" onkeyup="mask(this)" />
</form>
</BODY>