| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 520 人关注过本帖
标题:求解决!!!当输入的是2位的数字与输入的是3位数字时按小数点或者方上键 选择 ...
只看楼主 加入收藏
ppp230
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-12-30
收藏
 问题点数:0 回复次数:1 
求解决!!!当输入的是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>
搜索更多相关主题的帖子: 190 javascript 小数点 function 
2011-12-30 15:30
ppp230
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-12-30
收藏
得分:0 
这里有个问题 就是 当输入的是3位数字的时候,按小数点.select()选中的时候 可以完全覆盖以前写的,当是2位数字的时候之能加在前面不能 覆盖
2011-12-30 15:33
快速回复:求解决!!!当输入的是2位的数字与输入的是3位数字时按小数点或者方上键 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037706 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved