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>

  • 相关阅读:
    IT人士必去的10个网站
    c++怎样让函数返回数组
    vs中“Stack around the variable was corrupted”的解决方案
    c++ eof()函数
    bat开发小工具以及使用
    Python接口自动化(一)---json数据类型取值
    MAVEN编译错误解决:maven only whitespace content allowed before start
    shell常用命令总结总结
    shell打包和解压
    java总结笔记
  • 原文地址:https://www.cnblogs.com/zhouguoshuai/p/8317346.html
Copyright © 2011-2022 走看看