完全可用的WEB IP地址輸入框

來源:互聯網
上載者:User

滿3位元\ 按空格鍵\方向鍵\斷行符號鍵 自動跳到下一個 '.' 後面。

輸入必須是數字限制、0~255 範圍限制、

根據需要可能添加

地址有效性檢查、多播地址檢查等。

<style>div.IPDiv{background:#ffffff;width:120;font-size:9pt;text-align:center;border:2 ridge threedshadow;border-right:inset threedhighlight;border-bottom:inset threedhighlight;}input.IPInput{width:24;font-size:9pt;text-align:center;border-width:0;}</style><script language=javascript> function getPos(obj) {   obj.focus();   var workRange=document.selection.createRange();   obj.select();   var allRange=document.selection.createRange();   workRange.setEndPoint("StartToStart",allRange);   var len=workRange.text.length;   workRange.collapse(false);   workRange.select();   return len; }     function setCursor(obj,num) {   range=obj.createTextRange();    range.collapse(true);    range.moveStart('character',num);    range.select(); }   function keyDownEvent(obj) {     code=event.keyCode;     if(!((code>=48&&code<=57)||(code>=96&&code<=105)||code==190||code==110||code==13||code==9||code==39||code==8||code==46||code==99||    code==37))         event.returnValue=false;     if(code==13)         event.keyCode=9;     if(code==110||code==190)         if(obj.value)             event.keyCode=9;         else             event.returnValue=false; }   function keyUpEvent(obj0,obj1,obj2) {     if (obj1.value > 255)     {         alert("填寫範圍必須在 0 - 255間");         obj1.value = obj1.value.substring(0, obj1.value.length - 1);         return;     }     code=event.keyCode          if(obj1.value.length>=3&&code!=37&&code!=39&&code!=16&&code!=9&&code!=13)         obj2.focus();          if(code == 32)         obj2.focus();       if(code == 8 && obj1.value.length == 0)     {         obj0.focus();         setCursor(obj0,obj0.value.length);     }       if (code == 37 && (getPos(obj1) == 0))     {         obj0.focus();         setCursor(obj0,obj0.value.length);     }     if (code == 39 && (getPos(obj1) == obj1.value.length))     {         obj2.focus();     } } function keyUpEventForIp4(obj0,obj) {     if (obj.value > 255)     {         alert("填寫範圍必須在 0 - 255間");         obj.value = obj.value.substring(0, obj.value.length - 1);         return;     }     if(code == 8 && obj.value.length == 0)     {         obj0.focus();         setCursor(obj0,obj0.value.length);     }     if (code == 37 && (getPos(obj) == 0))     {         obj0.focus();         setCursor(obj0,obj0.value.length);     }   } function getipvalue(obj1,obj2,obj3,obj4,obj) {     obj.value = obj1.value + "." + obj2.value + "." + obj3.value + "." + obj4.value;     alert(obj.value); } </script> <script language="JScript">var IPlikeInputStr=[];//for(var i=0;i<4;i++)IPlikeInputStr[i]="<input class=IPInput name=IPInput type=text size=3 maxlength=3 >"+(i==3?"":".");IPlikeInputStr[0]="<input class=IPInput name=ip1 type=text size=3 maxlength=3 onkeydown=keyDownEvent(this) onkeyup=keyUpEvent(ip1,ip1,ip2)>."IPlikeInputStr[1]="<input class=IPInput name=ip2 type=text size=3 maxlength=3 onkeydown=keyDownEvent(this) onkeyup=keyUpEvent(ip1,ip2,ip3)>."IPlikeInputStr[2]="<input class=IPInput name=ip3 type=text size=3 maxlength=3 onkeydown=keyDownEvent(this) onkeyup=keyUpEvent(ip2,ip3,ip4)>."IPlikeInputStr[3]="<input class=IPInput name=ip4 type=text size=3 maxlength=3 onkeydown=keyDownEvent(this) onkeyup=keyUpEventForIp4(ip3,ip4)>"document.write("<div class=IPDiv>"+IPlikeInputStr.join("")+"</div>");</script>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.