首页 > 代码库 > js生成一个以零开头的八位数并且依次递增

js生成一个以零开头的八位数并且依次递增

条件:1八位数;2.以领开头;3.末尾要依次递增

<script type="text/javascript">
function RondomPass(number){
    var arr = new Array;
    var arr1 = new Array("0","1","2","3","4","5","6","7","8","9");
    
    for(var i=0;i<number;i++){
        var n = Math.floor(Math.random()*10);
        arr[i] =arr1[n] ;
        //document.write(arr1[n]);    
    }
    
    val = arr.join("")
    //document.write(val);
    return val;        
}

function Account(num,a){     // num以领开头的8位数,a依次递增    
    //初始的a为数字
    var s = a.toString();   // 数字转字符串
    var b =s.split("");    //字符串转数组
    var c = num-b.length;
    var e= new Array;
    for(var i=0;i<c;i++){
        e[i] = 0;  
    }
    var f = e.join("");    //数组转字符串
    
    return f;        
} 

var num = 30;     
for(var i=0;i<num;i++){
    document.write("账户");
    document.write(Account(8,i)+i);
    document.write("&nbsp;&nbsp;");
    
    document.write("密码");
    document.write(RondomPass(8));
    document.write("</br>");    
}
</script>