js验证码代码
樣式
js驗證碼代碼
var code; //在全局 定義驗證碼 function createCode() {code = "";var codeLength = 5;//驗證碼的長度var checkCode = document.getElementById("checkCode");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');//所有候選組成驗證碼的字符,當然也可以用中文的for (var i = 0; i < codeLength; i++) {var charIndex = Math.floor(Math.random() * 36);code += selectChar[charIndex];}//alert(code);if (checkCode) {checkCode.className = "code";checkCode.value = code;} }function validate() {var inputCode = document.querySelector('#bf_client .vcode').value;if (inputCode.length <= 0) {alert("請輸入驗證碼!");return false;} else if (inputCode != code) {alert("驗證碼輸入錯誤!");createCode();//刷新驗證碼return false;}else {return true;} }createCode();總結
- 上一篇: 创业日记
- 下一篇: i=1,为什么 (++i)+(++i)=