当前位置: 代码迷 >> Web前端 >> MAC地址一
  详细解决方案

MAC地址一

热度:271   发布时间:2012-10-26 10:30:59.0
MAC地址1
//MAC地址框
function MacField(macid){
this.macid = macid;
this.createMacDiv = function(){
if(null == document.getElementById(macid)){
var div = document.createElement("div");
div.id = macid;
div.style.marginBottom  = "5px";
document.body.appendChild(div);
}
document.getElementById(macid).innerHTML = '<div style="width:120;" id="macAddress">'+
'<input onkeyup="macHandlerFun(this,event,\''+macid+'\');" id="'+macid+'mac1" type="text" style="height:20px;font-size:12;width:37px;text-align:center;border:1px solid #ABC1FE" maxlength="4">'+
'<span>-</span>'+
'<input  id="'+macid+'mac2" onkeyup="macHandlerFun(this,event,\''+macid+'\');" type="text" style="height:20px;font-size:12;width:37px;text-align:center;border:1px solid #ABC1FE" maxlength="4">'+
'<span>-</span>'+
'<input id="'+macid+'mac3" onkeyup="macHandlerFun(this,event,\''+macid+'\');" type="text" style="height:20px;font-size:12;width:37px;text-align:center;border:1px solid #ABC1FE" maxlength="4"></div>';
};

this.getValue = function(){
return document.getElementById(macid+"mac1").value + "-" +
   document.getElementById(macid+"mac2").value + "-" +
   document.getElementById(macid+"mac3").value;
};

this.setValue = function(v){
var ss = v.split("-");
for(var i=0;i<ss.length;i++){
document.getElementById(macid+"mac"+(i+1)).value = ss[i];
}
};
this.setDisabled = function(b){
for(var i=1;i<=3;i++){
document.getElementById(macid+"mac"+i).disabled = b;
}
};
this.checkMac = function(){
var regex = /^[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}$/;
if(!regex.test(this.getValue()))
return false;
return true;
};
}
  相关解决方案