分享好友 资讯文章首页 资讯文章分类 切换频道

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

2023-03-23 10:32IP属地 广东佛山480建站助手
html中车牌号省份简称输入键盘的示例代码:

这篇文章主要介绍了html中车牌号省份简称输入键盘的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

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

具体实现代码如下,就不细说了。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<script type="text/javascript" src="../js/jquery-2.1.4.js"></script>
<style>

.content{
width:265px;
height:353px;
position:absolute;
top:50%;
left:50%;
height:50%;
margin:-177px 0 0 -132px;
}
.label_province{
position:absolute;
top:6px;
left:10px;
}
.input_province{
position:absolute;
text-align:center;
width:26px;
left:1px;
top:6px;
border:none;
outline:0;
font-family:"黑体";
}
.input_font{
font-size:18px;
color:#333333;
}
.input_font_plate{
font-size:14px;
color:#333333;
}
.input_platenumber_base{
position:absolute;
text-align:center;
width:34px;
top:13px;
border:none;
outline:0;
}
.input_city{
left:44px;
}

.label_platenumber{
font-size:14px;
color:#999;
width:265px;
text-align:center;
margin-top:29px;
border:0;
outline:0;
}

.input_park{
font-size:14px;
color:#666;
width:265px;
text-align:center;
border:0;
outline:0;
}

.label_btntext_/confirm/i{
position:absolute;
top:12px;
font-size:16px;
width:214px;
left:0;
}
.label_btn_text{
text-align:center;
color:#FFF;

}

.key_province{
font-size:17px;
position:absolute;
left:2.5px;
top:8px;
border:0;
width:28px;
text-align:center;
font-family:"黑体";
}

</style>
</head>
<body>
<div class="content">
<div style="margin-top:15px;">
<div style="height:40px;width:100%;position:relative;top:0;">
<img alt="" src="../img/bg_platenumber.png" width="257" height="40" style="position:relative;left:4px;">
<label class="label_province" for="id_province">
<img alt="" src="../img/border_province.png" width="28.5" height="28.5">
<input class="input_province" type="text" readonly="readonly" maxlength="1" id="id_province" onclick="provinceSelect();" value="冀">
</label>
<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">
<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">
<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">
<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">
<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">
<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">
</div>
<input type="text" readonly="readonly" class="label_platenumber" value="请绑定您的车牌号">
</div>

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

</div>
<div id="id_keyboard_province" style="display:none;">
</div>


<script type="text/javascript">

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

alert("选择停车场");
}
function confirm(){

alert("确定");
}

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

for(var i=0;i<rows;i++){
for(var j=0;j<columns;j++){
var provinceIds = i*columns+j;
if(provinceIds<provinces.length){
var x = 9+(j+1)*x_space+j*42;
var y = 12+i*48;

$("#id_keyboard_province").append(addKeyProvince(x,y,provinceIds));
}
else{
keyboard_province.style.display="block";
return;
}
}
}


}

function addKeyProvince(x,y,provinceIds){

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


function chooseProvince(province){

document.getElementById("id_province").value=province;
$("#id_keyboard_province").hide();
}
</script>
</body>
</html>

到此这篇关于html中车牌号省份简称输入键盘的示例代码的文章就介绍到这了,更多相关html车牌号输入键盘内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!

来源:脚本之家

链接:https://www.jb51.net/web/731451.html

举报
收藏 0
打赏 0
评论 0
哪吒GT被云评不行!哪吒CEO张勇猛怼键盘侠:跪久了 要不得
本月初,哪吒汽车旗下全新双门四座纯电跑车哪吒GT首发亮相,该车凭借着双门跑车的造型,迅速引起网友关注。不过,也有一些键盘侠对哪吒GT“吹毛求疵”,云评垃圾之类。没想到,哪吒汽车CEO张勇丝毫不惯键盘侠,火力全开在网上狂怼一通。4月9日,张勇又发微博,“二怼”部分喷子键盘侠。张勇表示:中国品牌,特别是新势力企业做一款代表高

2023-04-1020

网页bug却让人生气不起来,原来404页面文案能这么写!
网页bug却让人生气不起来,原来404页面文案能这么写!:这些404页面文案很赞!404页面时非常让人扫兴的。想想你正在兴致勃勃的看新闻、找资料、看视频,突然出现一个巨大的404,告诉你找的东西不存在,是不是有种想砸键盘的冲动?可偏偏有很多404页面让你看到之后不仅不会生气,还很期待再次看到他们。tip1:你的产品再烂也能写的有意思404页面算是很烂的产品了,但是依然

2023-03-2324

html表单控件禁用属性readonly VS disabled介绍
html表单控件禁用属性readonly VS disabled介绍:这篇文章主要介绍了html表单控件禁用属性readonly VS disabled区别,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下在html中有两种禁用表单提交的方法,他们分别是:1.给控件标签加上readonly='readonly'属性2.给控件标签

2023-03-2325

华为首款骁龙本评测:手机芯片做电脑 如今靠谱了么?
华为首款骁龙本评测:手机芯片做电脑 如今靠谱了么?:作为笔记本市场的新军,近几年华为虽然推出了多款MateBook笔记本电脑产品,其中不乏有亮点的产品比如新MateBook Pro和MateBook 14等。目前,华为所有的MateBook笔记本全部都采用的是英特尔处理器。可以说基于英特尔阵营的PC/笔记本市场已经是非常的成熟和稳固,大部分市场基本被联想、惠普等传统P

2023-03-1326

3999元 华为MateBook E GO 2023款开售:搭载骁龙8cx Gen3
2月13日0点,华为MateBook E GO 2023款正式开售,16GB+256GB版售价4299元,16+512GB版售价4999元,首发均优惠300元。华为MateBook E GO 2023款搭载了2.69GHz的骁龙8cx Gen3处理器,2023款与上一代性能版在文档办公、视频会议及视频影音等轻度使用场景下体验相当,当在长时间下中重度使用时,性能版体验更

2023-02-1350