html随机代码

1. demo.html < html > < head > </ head > < body > < form id = ' formseting' name = ' form1' method = ' POST' > < br >

1. demo.html

<html> 
<head></head> 
<body> 
<form id='formseting' name='form1' method='POST' >
<br> 
<input type="text" id = "lowerId" name="lowerMac">
<br>
<input type="text" id = "upperId" name="upperMac">
<input type="submit" value="Submit">    

<script> 

function print(msg) { document.write(msg);} 

function f1() {return Math.floor(Math.random()*255+1);};

function f2(x){
    if(x < 10) return "0"+x;
    else if(x < 16) return "0"+String.fromCharCode(x+55);
    else return x.toString(16);
}; 

function getVar(id) { return document.getElementById(id); };

//转成大写
function toupperStr (str){
    var result = '';
    for(var i= 0;i<str.length;i++){
        var temp = str.charAt(i);
        var code = temp.charCodeAt();
        if('a' <= temp && temp <= 'z'){
            temp= String.fromCharCode(code-32);
        }               
        result += temp;
    }
    return result;
}

//得到小写的mac地址
//00-93-cf-9b-d4-eb
function generateMacLower(){
    var s =  "00-" + f2(f1()) +"-" + f2(f1()) +"-" + f2(f1()) +"-" + f2(f1()) +"-" + f2(f1()); 
    return s;
}

//得到大写的mac地址
//00-B3-A9-39-35-42
function generateMac(){
    var ss = generateMacLower();
    return toupperStr(ss);
}

var macLower = generateMacLower(); 
var macstr = toupperStr(macLower); 
getVar("lowerId").value =  macLower;
getVar("upperId").value =  macstr;
for(var i=0;i<256;i++)
{
    print(f2(i)); 
    print(" ");
}

 
</script> 

</form> 
</body> 
</html>
2. 实际效果

在这里插入图片描述

知秋君
上一篇 2024-08-08 13:12
下一篇 2024-08-08 12:48

相关推荐