function getyzm() {
code = "";
var codeLength = 4; //驗證碼的長度
var checkCode = document.getElementById("show_yzm");
var selectChar = 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'); //所有候選組成驗證碼的字符,當然也可以用中文的
for(var i = 0; i < codeLength; i++) {
var charIndex = Math.floor(Math.random() * 52); //Math.random得到0-36中隨機的一個數,floor取整數部分
code += selectChar[charIndex];
}
// alert(code);
if(checkCode) {
checkCode.value = code;
}
}
function validate() {
var inputCode = document.getElementById("yzm").value;
if(inputCode.length <= 0) {
alert("請輸入驗證碼!");
} else if(inputCode.toLowerCase() != code.toLowerCase()) {
alert("驗證碼輸入錯誤!");
createCode(); //刷新驗證碼
} else {
alert("驗證成功");
}
}