• javascript——数字验证码


    View Code
     1 <script type="text/javascript">
     2         function validateCode() {
     3             var validatevalue = "";
     4             var codes = new Array(4);
     5             var colors = new Array("Red", "Green", "Gray", "Blue", "Maroon", "Aqua", "Fuchsia", "Lime", "Olive", "Silver");
     6             for (var i = 0; i < codes.length; i++) {
     7                 codes[i] = Math.floor(Math.random() * 10);
     8                 validatevalue += codes[i];
     9             }
    10             var spans = document.getElementById("divCode").all;
    11             for (var i = 0; i < spans.length; i++) {
    12                 spans[i].innerText = codes[i];
    13                 spans[i].style.color = colors[Math.floor(Math.random() * 10)];
    14             }
    15             document.getElementById("validatevalue").value = validatevalue;
    16         }
    17 
    18         function validate() {
    19             if (document.getElementById("textfield3").value != document.getElementById("validatevalue").value) {
    20                 alert("验证码错误");
    21                 validateCode();
    22                 document.getElementById("textfield3").value = "";
    23                 document.getElementById("textfield3").focus();
    24                 return false;
    25             } else {
    26                 return true;
    27             }
    28         }
    29         document.onload = validateCode();
    30     </script>
  • 相关阅读:
    |,&,<<,>>运算符
    Unity 异步加载场景
    string字母排序,
    冒泡算法
    Direct3D 12 编程---(1)
    点云密度粗估计
    git工具使用
    opencv---灰度图像与彩色图像遍历
    求平面两直线的交点,两直线段的交点
    结构体重载运算符
  • 原文地址:https://www.cnblogs.com/daishuguang/p/3025227.html
Copyright © 2020-2023  润新知