欢迎光临
我们一直在努力

关于IP验证的一个例子-ASP教程,客户端相关

建站超值云服务器,限时71元/月

平时感觉windows的ip输入框很好用,如果再网页中也能实现一定是很爽的事情。核心代码如下:

<script language="javascript">

function outstr(){

if(document.all.ip1.value>0 && document.all.ip2.value>0 && document.all.ip3.value>0 && document.all.ip4.value>0){

alert("你输入的ip地址为:" + document.all.ip1.value + "." + document.all.ip2.value + "." + document.all.ip3.value + "." + document.all.ip4.value);

}//end if

}//end

function moveright(obj){

id = parseint(obj.name.substr(2,1))

if(id<4){

eval("document.all.ip" + (id +1) + ".focus()");

}else{

outstr();

}//end if

}

function moveleft(obj){

id = parseint(obj.name.substr(2,1))

if(id>1){

eval("document.all.ip" + (id -1) + ".focus()");

}//end if

}//end if

function keypress(obj){

var objinput = obj;

cod = window.event.keycode;

if(cod==46 && (obj.value).length>0){//如果按了“.”并且有了一个字符,向右移动一次

window.event.keycode=0;

moveright(obj);

}else if((obj.value).length==2 && (cod >= 48) && (cod <= 57)){//如果数字键并且够了两位

if(cod<58){//

obj.value = obj.value * 10 + cod – 48;

}//end if

window.event.keycode = 0;

moveright(obj);

}else{ //判断输入的是不是数字

if ( !(((cod >= 48) && (cod <= 57)) || (cod == 13) || (cod == 37) || (cod == 39))){

window.event.keycode = 0;

}//end if

}//end if

}//end function keydown

function getcaretpos(obj){

var currentrange=document.selection.createrange();

var workrange=currentrange.duplicate();

obj.select();

var allrange=document.selection.createrange();

var len=0;

while(workrange.compareendpoints("starttostart",allrange)>0){

workrange.movestart("character",-1);

len++;

}

currentrange.select();

return len;

}//end

function keydown(obj){

cod = window.event.keycode;

i = getcaretpos(obj); //光标位置

n = obj.value.length; //字符长度

if(cod==37 && i==0){//光标左移

moveleft(obj);

}else if(cod==39 && i>=n){

moveright(obj);

}else if(cod==8 && (obj.value=="" || i==0)){

moveleft(obj);

}//end if

}//end

function checkdate(obj,max_num){

if(obj.value>max_num || obj.value<0){

window.event.keycode = 0;

alert(obj.value + "是无效的项目,只能输入0到" + max_num + "之间的数。");

obj.value = max_num;

obj.focus();

obj.select();

}//end if

}//end

</script>

测试网址:http://yuenshui.3c21.com/test/ipv1.0.htm

源代码全部在网页中,没有任何加密,希望使用时不要去掉出处。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 关于IP验证的一个例子-ASP教程,客户端相关
分享到: 更多 (0)

相关推荐

  • 暂无文章