zoukankan      html  css  js  c++  java
  • Math.random()随机生成车牌号

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" lang="en">

        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <title>随机生成车辆号牌</title>
            <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
            <script type="text/javascript">
                //
                //省的简称(一个汉字)
                //城市的编号
                //·对焦符号
                //五位的数字或者字母(不包含字母I和O)
                $(function() {
                    $("#getCarId").click(function() {
                        console.debug("随机数:" + Math.random());
                        var shi = new Array("A", "B", "C");
                        var carId = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");

                        var $objArr = $("input[name='choose']");
                        var count = 0;
                        for(var i = 0; i < $objArr.length; i++) {
                            if($objArr[i].checked) {
                                count = $($objArr[i]).val();
                            }
                        }
                        console.debug("选择生成" + count + "个号牌!");
                        $("div#main").empty();
                        for(var j = 0; j < count; j++) {
                            var shiIndex = parseInt(Math.random() * 3);
                            //console.debug("随机生成0-2之间的数(包含0和2):" + shiIndex);
                            var carNumber = "云" + shi[shiIndex] + "·";
                            console.debug("随机生成车牌对焦点前面的内容:" + carNumber);
                            for(var i = 0; i < 5; i++) {
                                carNumber += carId[parseInt(Math.random() * carId.length - 1)];
                            }
                            console.debug("生成的号牌是:" + carNumber);

                            //添加到页面上
                            var $divObj = $("<div></div>");
                            $divObj.addClass("carId");
                            //$divObj.attr("class","carId");
                            $divObj.text(carNumber);
                            $("div#main").append($divObj);
                        }
                    });
                });
            </script>
            <style type="text/css">
                div.carId {
                     220px;
                    height: 50px;
                    background-color: mediumblue;
                    color: white;
                    font-family: "微软雅黑";
                    font-size: 26pt;
                    text-align: center;
                    border: double 4px white;
                    border-radius: 10px;
                    float: left;
                }
            </style>
        </head>

        <body>
            <input type="radio" name="choose" value="10" />10个
            <input type="radio" name="choose" value="20" checked="checked" />20个
            <input type="radio" name="choose" value="50" />50个
            <input type="button" value="随机生成" id="getCarId" />
            <div id="main">
                <!--<div class="carId">
                    云A·33478
                </div>-->
            </div>
        </body>

    </html>

  • 相关阅读:
    什么是回归测试?
    单元测试、集成测试、系统测试的侧重点是什么?
    一个测试工程师应具备那些素质?
    你所了解的的软件测试类型都有哪些,简单介绍一下。
    Python
    爬虫-urllib3模块的使用
    爬图片(附,源码)
    MySQL存储引擎:MyISAM和InnoDB的区别
    员工管理系统
    MySQL锁(二)表锁:为什么给小表加字段会导致整个库挂掉?
  • 原文地址:https://www.cnblogs.com/zhouguoshuai/p/8317346.html
Copyright © 2011-2022 走看看