1. 程式人生 > >JS隨機生成6為數字並賦值給input

JS隨機生成6為數字並賦值給input

<html>
<head>
</head>
<script>
function code(){
        var Num="";
        for(var i=0;i<6;i++){
            Num+=Math.floor(Math.random()*10);
        }
        document.getElementById("codes").value=Num;
    }
</script>
<body>
<input type="text" name="code" id="codes">
<input type="botton" value="yanzhengma" onclick="code()">
</body>
</html>