zoukankan      html  css  js  c++  java
  • 利用随机数生成一个简单的验证码

    在网站上随处可见各种类型的验证码:

    这里说一下最简单的验证码只包括前台;思路就是利用js中的随机数,生成简单的验证码:

    这里面的数字是四位的,公式是parseint(Math.random(max-min+1)*min);//max最大的数 min最小的数

    代码:

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
            <style>
            *{margin:0px;padding:0px;}
            div{100px;height:50px;border:1px solid #000;margin:100px auto;background:url(1.png);color:#fff;letter-spacing:7px;font-weight:bold;font-size:18px;text-align:center;line-height:50px;}
            </style>
            <script src="jquery-1.7.2.js"></script>
            <script>
            $(function(){
                yan();
                function yan(){
                    var num=parseInt(Math.random()*(9999-1000+1)+1000);
                    $("div").html(num);
                };
                $("div").click(function(){
                    yan();
                });
                
            });
            </script>
        </head>
        <body>
        <div></div>
        </body>
    </html>
  • 相关阅读:
    Sublime Text 2快捷键大全
    JavaSE
    Ubuntu16.04 install ideaIC-2017.2.5.tar.gz
    Ubuntu/CentOS hadoop-2.x Cluster Setup
    Ubuntu16.04 install hadoop-2.8.1.tar.gz Cluster Setup
    12file
    11input/output
    10function
    09FlowControl
    08test
  • 原文地址:https://www.cnblogs.com/GainLoss/p/6264041.html
Copyright © 2011-2022 走看看