1. 程式人生 > >Javascript隨機驗證碼

Javascript隨機驗證碼

javascrip utf-8 code var asc return valid and ++

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>隨機驗證碼</title>
</head>
<body>
<span id="msg"></span>
<input type="button" value="刷新" onclick="show()">
<script>
function validateCode(n){
var s="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
var ret="";
for(var i=0;i<n;i++){
var index=Math.floor(Math.random()*62);
ret+= s.charAt(index);
// alert(Math.floor(Math.random()*62));
}
return ret;
}
function show(){
document.getElementById("msg").innerHTML=validateCode(5);
}
function renovates(){
document.location.reload();
}
window.onload=show;
</script>
</body>
</html>

Javascript隨機驗證碼