• 设为首页
  • 收藏本站
  • 积分充值
  • VIP赞助
  • 手机版
  • 微博
  • 微信
    微信公众号 添加方式:
    1:搜索微信号(888888
    2:扫描左侧二维码
  • 快捷导航
    福建二哥 门户 查看主题

    html中车牌号省份简称输入键盘的示例代码

    发布者: 浪子 | 发布时间: 2025-8-13 07:06| 查看数: 8| 评论数: 0|帖子模式

    原理是先写出一个按键的div,然后再根据屏幕的大小去自动适应生成键盘,效果如下图:


    具体实现代码如下,就不细说了。
    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4.     <meta charset="UTF-8">
    5.     <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    6.     <script type="text/javascript"  src="../js/jquery-2.1.4.js"></script>
    7.     <style>
    8.         /* *{
    9.             font-family:"黑体";
    10.         } */
    11.         .content{
    12.             width:265px;
    13.             height:353px;
    14.             position:absolute;
    15.             top:50%;
    16.             left:50%;
    17.             height:50%;
    18.             margin:-177px 0 0 -132px;
    19.         }
    20.         .label_province{
    21.             position:absolute;
    22.             top:6px;
    23.             left:10px;
    24.         }
    25.         .input_province{
    26.             position:absolute;
    27.             text-align:center;
    28.             width:26px;
    29.             left:1px;
    30.             top:6px;
    31.             border:none;
    32.             outline:0;  
    33.             font-family:"黑体";      
    34.         }
    35.         .input_font{
    36.             font-size:18px;
    37.             color:#333333;
    38.         }
    39.         .input_font_plate{
    40.             font-size:14px;
    41.             color:#333333;
    42.         }
    43.         .input_platenumber_base{
    44.             position:absolute;
    45.             text-align:center;
    46.             width:34px;
    47.             top:13px;
    48.             border:none;
    49.             outline:0;
    50.         }
    51.         .input_city{
    52.             left:44px;
    53.         }

    54.         .label_platenumber{
    55.             font-size:14px;
    56.             color:#999;
    57.             width:265px;
    58.             text-align:center;
    59.             margin-top:29px;
    60.             border:0;
    61.             outline:0;
    62.         }

    63.         .input_park{
    64.             font-size:14px;
    65.             color:#666;
    66.             width:265px;
    67.             text-align:center;
    68.             border:0;
    69.             outline:0;
    70.         }

    71.             .label_btntext_confirm{
    72.             position:absolute;
    73.             top:12px;
    74.             font-size:16px;
    75.             width:214px;
    76.             left:0;
    77.         }
    78.         .label_btn_text{
    79.             text-align:center;
    80.             color:#FFF;
    81.             /* font-weight:bold; */
    82.         }

    83.         .key_province{
    84.             font-size:17px;
    85.             position:absolute;
    86.             left:2.5px;
    87.             top:8px;
    88.             border:0;
    89.             width:28px;
    90.             text-align:center;
    91.             font-family:"黑体";
    92.         }

    93.     </style>
    94. </head>
    95. <body>
    96.     <div class="content">
    97.         <div style="margin-top:15px;">
    98.             <div style="height:40px;width:100%;position:relative;top:0;">
    99.                 <img alt="" src="../img/bg_platenumber.png" width="257" height="40" style="position:relative;left:4px;">
    100.                 <label class="label_province" for="id_province">
    101.                     <img alt="" src="../img/border_province.png" width="28.5" height="28.5">
    102.                     <input class="input_province" type="text" readonly="readonly" maxlength="1" id="id_province" onclick="provinceSelect();" value="冀">
    103.                 </label>
    104.                 <input id="id_city" class="input_platenumber_base input_platenumber_base" style="left:45px;" type="text" onkeyup="value=value.replace(/[^[A-Z]+$/g,'')" maxlength="1">
    105.                 <input id="id_plate1" class="input_platenumber_base input_platenumber_base" style="left:81px;" type="text" onkeyup="value=value.replace(/[^[A-Z0-9]+$/g,'')" maxlength="1">
    106.                 <input id="id_plate2" class="input_platenumber_base input_platenumber_base" style="left:117px;" type="text" onkeyup="value=value.replace(/[^[A-Z0-9]+$/g,'')" maxlength="1">
    107.                 <input id="id_plate3" class="input_platenumber_base input_platenumber_base" style="left:153px;" type="text" onkeyup="value=value.replace(/[^[A-Z0-9]+$/g,'')" maxlength="1">
    108.                 <input id="id_plate4" class="input_platenumber_base input_platenumber_base" style="left:189px;" type="text" onkeyup="value=value.replace(/[^[A-Z0-9]+$/g,'')" maxlength="1">
    109.                 <input id="id_plate5" class="input_platenumber_base input_platenumber_base" style="left:225px;" type="text" onkeyup="value=value.replace(/[^[A-Z0-9]+$/g,'')" maxlength="1">
    110.             </div>
    111.             <input type="text" readonly="readonly" class="label_platenumber" value="请绑定您的车牌号">
    112.         </div>

    113.         <div style="margin-top:91px;">
    114.             <div>
    115.                 <input id="id_park" type="text" readonly="readonly" class="input_park" placeholder="请选择您的停车场" onclick="parkSelect();">
    116.             </div>
    117.             <div>
    118.                 <hr  id="username_devision" size=1 color=#ececec style="FILTER: alpha(opacity=100,finishopacity=0);margin-left:22px;margin-right:22px;"/>
    119.             </div>
    120.         </div>
    121.         <div style="margin-top:90px;position:relative;top:0;left:26px;width:214px;">
    122.             <label for="confirm">
    123.                 <img id="img_confirm" width="214" height="39" alt="" src="../img/bg_btn_enable.png">
    124.             </label>
    125.             <label for="confirm" class="label_btntext_confirm label_btn_text">确定</label>
    126.             <button type="submit" id="confirm" name="button" style="display:none;" onclick="confirm();">确定</button>
    127.         </div>

    128.     </div>
    129.         <div id="id_keyboard_province" style="display:none;">
    130.     </div>


    131. <script type="text/javascript">

    132.     var provinces = new Array("京","沪","浙","苏","粤","鲁","晋","冀",
    133.             "豫","川","渝","辽","吉","黑","皖","鄂",
    134.             "津","贵","云","桂","琼","青","新","藏",
    135.             "蒙","宁","甘","陕","闽","赣","湘");
    136.     function provinceSelect(){
    137.         showProvince();
    138.     }
    139.     function parkSelect(){

    140.         alert("选择停车场");
    141.     }
    142.     function confirm(){

    143.         alert("确定");
    144.     }

    145.     function showProvince(){
    146.         var screenWidth=window.screen.width;
    147.         //求出列数,向下取整
    148.         var columns = Math.floor((screenWidth - 9)/42);
    149.         //求出行数,向上取整
    150.         var rows = Math.ceil(31/columns);
    151.         //算出按键背景的高度,为每个按键的高度+间隔+上下边距,48为每个按键的高度+距下一个按键的距离
    152.         var key_bg_height= rows*48+16;
    153.         var x_space = (screenWidth - 9 - 42*columns)/(columns);
    154.         var start_x = 9+x_space;
    155.         var start_y = 12;
    156.         var keyboard_province = document.getElementById("id_keyboard_province");
    157.         keyboard_province.style.position="fixed";
    158.         keyboard_province.style.top= (window.screen.height-key_bg_height)+"px";
    159.         keyboard_province.style.left=0;
    160.         keyboard_province.style.backgroundColor="#f2f2f2";
    161.         keyboard_province.style.width="100%";
    162.         keyboard_province.style.height=key_bg_height+"px";
    163.         //keyboard_province.style.display="block";
    164.         keyboard_province.innerHTML = '';

    165.         for(var i=0;i<rows;i++){
    166.             for(var j=0;j<columns;j++){
    167.                 var provinceIds = i*columns+j;
    168.                 if(provinceIds<provinces.length){
    169.                     var x = 9+(j+1)*x_space+j*42;
    170.                     var y = 12+i*48;
    171.                     /* var addHtml = addKeyProvince(x,y,provinceIds);
    172.                     alert(addHtml); */
    173.                     $("#id_keyboard_province").append(addKeyProvince(x,y,provinceIds));
    174.                 }
    175.                 else{
    176.                     keyboard_province.style.display="block";
    177.                     return;
    178.                 }
    179.             }
    180.         }


    181.     }

    182.     function addKeyProvince(x,y,provinceIds){

    183.         var addHtml = '<div style="position:absolute;left:'+x+'px;top:'+y+'px;width:42px;height:48px;">';
    184.             addHtml += '<label for="id_'+provinceIds+'"><img alt="" width="34" height="38" src="../img/bg_key_province.png"></label>';
    185.             addHtml += '<input id="id_'+provinceIds+'" type="text" readonly="readonly" class="key_province" value="'+provinces[provinceIds]+'" onclick="chooseProvince(this.value);">';
    186.             addHtml += '</div>';
    187.             return addHtml;
    188.     }


    189.     function chooseProvince(province){
    190.         /* alert(province+"======"+provinces[7]); */
    191.         document.getElementById("id_province").value=province;
    192.         $("#id_keyboard_province").hide();
    193.     }
    194. </script>
    195. </body>
    196. </html>
    复制代码
    到此这篇关于html中车牌号省份简称输入键盘的示例代码的文章就介绍到这了,更多相关html车牌号输入键盘内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!

    来源:互联网
    免责声明:如果侵犯了您的权益,请联系站长(1277306191@qq.com),我们会及时删除侵权内容,谢谢合作!

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    ×

    最新评论

    QQ Archiver 手机版 小黑屋 福建二哥 ( 闽ICP备2022004717号|闽公网安备35052402000345号 )

    Powered by Discuz! X3.5 © 2001-2023

    快速回复 返回顶部 返回列表