生成含有字母数字任意位数的验证码

来源:互联网 发布:西门子plc简单编程实例 编辑:程序博客网 时间:2024/06/07 11:51

function getCode(length){
                if(length=="undefined"){
                    length=4;
                }
                var rand,
                    current=0,
                    code="";
                while(current<length){
                    rand=Math.floor(Math.random()*(122-48+1)+48);
                    if(rand<65&&rand>57||rand<97&&rand>90){
                        continue;
                    }
                        code+=String.fromCharCode(rand);
                        current++;
                }
                return code
            }
            document.write(getCode(6))

0 0
原创粉丝点击