首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

IP地址一

2012-11-07 
IP地址1//IP地址框function IpField(ipid){this.ipid ipidthis.createIpDivfunction(){if(null doc

IP地址1
//IP地址框
function IpField(ipid){

this.ipid = ipid;

this.createIpDiv=function(){
if(null == document.getElementById(ipid)){
var div = document.createElement("div");
div.id = ipid;
div.style.marginBottom  = "5px";
document.body.appendChild(div);
}
var isIe = (document.all)?true:false;
if(isIe){
document.getElementById(ipid).innerHTML = '<div id="ip" style="border:1px solid #ABC1FE;width:120px;height:20px;display:inline;background:white">'+
'<input type="text" maxlength="3" id="'+ipid+'ip1" onkeyup="changeCursor(this,event,\''+ipid+'\');" style="height:18px;border:0px;width:25px;text-align:center;"/>'+
'<span style="font-size:12px;border:0px;">.</span>'+
'<input type="text" maxlength="3" id="'+ipid+'ip2" onkeyup="changeCursor(this,event,\''+ipid+'\');" style="height:18px;border:0px;width:26px;text-align:center;"/>'+
'<span style="font-size:15px;border:0px;">.</span>'+
'<input type="text" maxlength="3" id="'+ipid+'ip3" onkeyup="changeCursor(this,event,\''+ipid+'\');" style="height:18px;border:0px;width:26px;text-align:center;"/>'+
'<span style="font-size:15px;border:0px;">.</span>'+
'<input type="text" maxlength="3" id="'+ipid+'ip4" onkeyup="changeCursor(this,event,\''+ipid+'\');" style="height:18px;border:0px;width:25px;text-align:center;"/></div><div style="display:inline" id="xuguoanip"></div>';
}else{
document.getElementById(ipid).innerHTML = '<div id="ip" style="border:1px solid #ABC1FE;width:120px;height:21;background:white">'+
'<input type="text" maxlength="3" id="'+ipid+'ip1" onkeyup="changeCursor(this,event,\''+ipid+'\');" style="height:18px;border:0px;width:24px;text-align:center;"/>'+
'<span style="font-size:15px;height:20;border:0px;">.</span>'+
'<input type="text" maxlength="3" id="'+ipid+'ip2" onkeyup="changeCursor(this,event,\''+ipid+'\');" style="height:18px;border:0px;width:24px;text-align:center;"/>'+
'<span style="font-size:15px;height:20;border:0px;">.</span>'+
'<input type="text" maxlength="3" id="'+ipid+'ip3" onkeyup="changeCursor(this,event,\''+ipid+'\');" style="height:18px;border:0px;width:24px;text-align:center;"/>'+
'<span style="font-size:15px;height:20;border:0px;">.</span>'+
'<input type="text" maxlength="3" id="'+ipid+'ip4" onkeyup="changeCursor(this,event,\''+ipid+'\');" style="height:18px;border:0px;width:24px;text-align:center;"/></div><div style="display:inline" id="xuguoanip"></div>';
}
};

this.getValue = function(){
return document.getElementById(ipid+"ip1").value + "." +
   document.getElementById(ipid+"ip2").value + "." +
   document.getElementById(ipid+"ip3").value + "." +
   document.getElementById(ipid+"ip4").value;
};
this.setValue = function(v){
if(v == "" || v==undefined)return;
var ss = v.split(".");
for(var i=0;i<ss.length;i++){
document.getElementById(ipid+"ip"+(i+1)).value = ss[i];
}
};
this.setDisabled = function(b){
for(var i=1;i<=4;i++){
document.getElementById(ipid+"ip"+i).disabled = b;
}
};
this.checkIp = function(){
var regex = /^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$/;
if(!regex.test(this.getValue()))
return false;
for(var i=1;i<=4;i++){
if(document.getElementById(ipid+"ip"+i).value > 255){
return false;
}
}
return true;
};
this.clearIp = function(){
for(var i=1;i<=4;i++){
document.getElementById(ipid+"ip"+i).value = "";
}
};
}

热点排行