//
lianxi.js代码
//取随机数验证码
//1.要随机的值放入到数组中
var arr = [0,1,2,3,4,5,6,7,8,9,
'a','b','c','d','e','f','g','h','i'
'g','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','G',
'K','L','M','N','O','P','Q','R','S',
'T','U','V','W','X','Y','Z'];
var str='';
//2.随机取4次
for(var i=0;i<4;i++){
//产生0~数组长度之间的随机数(小数)
var num = Math.random()*arr.length;
//产生0~数组长度之间的随机数
num = Math.floor(num);
//arr[num]
//通过随机下标找到数组中的元素
str += arr[num];
}
console.log(str);
//用户反复输入
while(true){
var code = prompt('please input code');
//如果输入的和验证码一致
if(code == str){
alert('login success');
break;//终止循环
}
}
//1.要随机的值放入到数组中
var arr = [0,1,2,3,4,5,6,7,8,9,
'a','b','c','d','e','f','g','h','i'
'g','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','G',
'K','L','M','N','O','P','Q','R','S',
'T','U','V','W','X','Y','Z'];
var str='';
//2.随机取4次
for(var i=0;i<4;i++){
//产生0~数组长度之间的随机数(小数)
var num = Math.random()*arr.length;
//产生0~数组长度之间的随机数
num = Math.floor(num);
//arr[num]
//通过随机下标找到数组中的元素
str += arr[num];
}
console.log(str);
//用户反复输入
while(true){
var code = prompt('please input code');
//如果输入的和验证码一致
if(code == str){
alert('login success');
break;//终止循环
}
}
//html代码
<script src="lianxi.js"></script>
//js和html代码必须在同一目录下