function get_code(code_length){ //验证码设置 var rand_aa=""; //最终的结果 var code=new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"); //设置需要参加验证的数字或字母 var code_Num=code.length; //数组的长度 for(i=0;i<code_length;i++){ //做一个循环,从里面抽取 //Math.random()随机抽取后续的数组里面的元素 //parseInt 取得整数,也就是把随机取出的数组下标取整 var ran_ss=parseInt(Math.random()*code_Num); rand_aa+=String(code[ran_ss]); //将元素加入到结果里面 } document.write("<input type=text name=check_code size="+code_length+" value="+rand_aa+" class=blank_bg maxsize=10 readonly=true>");//对数组进行输出 }