js生成mac地址代码
js计算日期之间天数,js计算日期间隔多少天代码教程如下:
1.选择MAC地址格式
2.自定义MAC地址前缀
得出:生成自定义前缀的MAC地址
js实现代码:
function calculate() {
var type = document.getElementById("in1").value;
var ran1 =document.getElementById("rd").value;
document.getElementById("error1").innerHTML="";
if(ran1!=''){
if(ran1.length==2&& ishex(ran1)){
}else{
document.getElementById("error1").innerHTML="杈撳叆鏈夋晥鍓嶇紑銆�";
document.getElementById("rd").focus();
return false;
}
}
else{
ran1 = Math.floor(Math.random()*256);
ran1 = ran1.toString(16).toUpperCase();
}
if(ran1.length==1)
ran1= "0"+ran1;
var ran2 = Math.floor(Math.random()*256);
ran2 = ran2.toString(16).toUpperCase();
if(ran2.length==1)
ran2= "0"+ran2;
var ran3 = Math.floor(Math.random()*256);
ran3 = ran3.toString(16).toUpperCase();
if(ran3.length==1)
ran3= "0"+ran3;
var ran4 = Math.floor(Math.random()*256);
ran4 = ran4.toString(16).toUpperCase();
if(ran4.length==1)
ran4= "0"+ran4;
var ran5 = Math.floor(Math.random()*256);
ran5 = ran5.toString(16).toUpperCase();
if(ran5.length==1)
ran5= "0"+ran5;
var ran6 = Math.floor(Math.random()*256);
ran6 = ran6.toString(16).toUpperCase();
if(ran6.length==1)
ran6= "0"+ran6;
var res = "";
if(type == 1){
res = ran1 +":"+ran2+":"+ran3+":"+ran4+":"+ran5+":"+ran6;
}else if(type == 2){
res = ran1 +"-"+ran2+"-"+ran3+"-"+ran4+"-"+ran5+"-"+ran6;
}else if(type == 3){
res = ran1 +" "+ran2+" "+ran3+" "+ran4+" "+ran5+" "+ran6;
}
document.getElementById("result1").innerHTML=res;
}
function ishex(num){
var validChar='0123456789ABCDEF';
var flag=true;
var x=num.toUpperCase();
for(idx=0;idx<x.length;idx++){
if(validChar.indexOf(x.charAt(idx))<0){
return false;
}
}
return true;
}
显示效果图:http://www.chinawe.net/tools/mac/
参考文章:http://www.itmacom.com/jc/33449.html