html5自定义数字键盘

原理:使用div模拟输入框,避免手机原生键盘弹出,键盘使用div模拟,点击事件使用js控制,光标闪烁使用css模拟,具体代码如下:

 1 <!doctype html>
 2 <html lang="zh">
 3 <head>
 4     <meta charset="UTF-8">
 5     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 6     <meta name="viewport" content="width=device-width, initial-scale=1.0">
 7     <title>key</title>
 8
 9 <style>
10 .main{width: 200px; margin:0 auto}
11 .num{width: 200px;height: 30px; line-height:30px; border: 1px solid #666;}
12 .num span{position: relative;display: inline-block; min-width: 1px; height: 30px;}
13 .num.active span:after{content: ‘‘; position: absolute; right: -2px; top: 4px; height: 20px; width: 1px; background: #000; animation: 1s linear infinite blink; -webkit-animation: 1s linear infinite blink;}
14 @keyframes blink{
15     0%{
16         width: 1px;
17     }
18     49.9999%{
19         width: 1px;
20     }
21     50%{
22         width: 0;
23     }
24     100%{
25         width: 0;
26     }
27 }
28 @-webkit-keyframes blink{
29     0%{
30         width: 1px;
31     }
32     49.9999%{
33         width: 1px;
34     }
35     50%{
36         width: 0;
37     }
38     100%{
39         width: 0;
40     }
41 }
42 .key{ display: none;height: 120px; width: 250px; position: absolute;left:60px;bottom:50px;}
43 .kc{width: 160px;float: left;}
44 .key span{float: left; width: 30px;height: 30px; margin:10px 10px 0 10px; line-height:30px;text-align: center;border: 1px solid #666;}
45 .key em{width: 80px;float: left;}
46 .key em i{display: block;width: 60px;height: 30px; margin:10px 0 10px 0; line-height:30px;text-align: center;border: 1px solid #666; font-style:normal}
47 .key em .next{height: 70px; line-height:70px; margin:10px 0  0;}
48 </style>
49 </head>
50 <body>
51 <div class="main">
52 <div class="num"><span></span></div>
53     <div class="key">
54     <div class="kc"><span>1</span><span>2</span><span>3</span><span>4</span><span>5</span><span>6</span>
55     <span>7</span><span>8</span><span>9</span></div>
56     <em><i class="del">删除</i><i class="next">下一题</i></em>
57     </div>
58     </div>
59     <script src="js/jquery.min.js" type="text/javascript"></script>
60     <script type="text/javascript">
61         $(".num").click(function(){
62             $(".key").show();
63             $(this).addClass("active");
64             return false;
65         });
66
67         $(document).click(function () {
68             $(".num").removeClass("active");
69             $(".key").hide();
70         });
71
72         $(".key").click(function () {
73             return false;
74         });
75
76         $(".key span").click(function(){
77             var key = $(this).text();
78             $(".num span").html($(".num span").html()+key);
79             })
80         $(".del").click(function(){
81             $(".num span").html($(".num span").html().substr(0,$(".num span").html().length-1));
82
83             })
84
85     </script>
86 </body>
87 </html>
时间: 2024-08-13 14:46:13

html5自定义数字键盘的相关文章

一个高仿闲鱼键自定义数字键盘特效

博客地址: http://www.jianshu.com/p/be68facfc4b8 仿造android端闲鱼发布选择价格数字键盘,自定义数字键盘 public class MyKeyBoardView extends KeyboardView { private Context mContext; private Keyboard mKeyBoard; public MyKeyBoardView(Context context, AttributeSet attrs) { super(con

Android 自定义数字键盘

业务需求自定义数字键盘,写了一个demo 主要代码: import android.app.Activity; import android.content.Context; import android.graphics.drawable.ColorDrawable; import android.util.DisplayMetrics; import android.view.View; import android.view.WindowManager; import android.vi

自定义数字键盘组件化方案

实现场景:点击输入框,弹出自定义数字键盘,输入数字后点击确定,输入框中显示对应数字.如果输入框中有值,则默认带到小键盘中. 其中:数字键盘为子组件.输入框公用该子组件. 效果图如下: 难点: 1.props传入数字键盘组件中的值,无法直接修改.需要通过计算属性进行修改. 2.公用键盘时,保证符合预期,数字不会错乱.使用v-for,巧用name属性,通过点击时更改传入的参数,达到目的. 下面时完整代码: index.vue <template> <view class="cont

iOS自定义数字键盘

自定义键盘实际就是设置UITextField的inputView属性,首先我们要做的是自定义一个UIView,实现键盘的样式. 自定义View代码如下: 1 #import <UIKit/UIKit.h> 2 //创建自定义键盘协议 3 @protocol My_KeyBoardDelegate <NSObject> 4 //创建协议方法 5 @required//必须执行的方法 6 - (void)numberKeyBoard:(NSInteger) number; 7 - (v

GridLayout自定义数字键盘(两个EditText)

功能说明: 适用于两个EditText输入框,并控制输入字符的长度,点击键盘中的"确定"按钮完成输入,点击"前一项"光标跳到前一个EditText 运行效果图如下: 布局文件 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/androi

GridView+PopupWindow自定义数字键盘

public class SimpleGridViewTest extends Activity {EditText editText;private PopupWindow popupWindow;private GridView mGridView;private View contentview;private List<String> datas = new ArrayList<String>();GridViewAdapter adapter;private static

Android 自定义的数字键盘 支持随意拖动 和稳定的字符输入的控件

经过 研究 实现了自定义 键盘 ,支持随意拖动 和数字及其他字符输入 下面是主要的代码 和使用方法 import android.content.Context; import android.util.Log; import android.view.GestureDetector; import android.view.GestureDetector.OnGestureListener; import android.view.Gravity; import android.view.Mo

iOS数字键盘自定义按键

UIKeyboardTypeNumberPad 数字键盘自定义按键 最近做一个搜索用户的功能,这里使用了UISearchBar.由于搜索的方式只有手机号码,所以这里的键盘要限制为数字输入,可以这么做: self.searchBar.keyboardType = UIKeyboardTypeNumberPad; 如果使用的不是搜索框而是textField输入框,可以设置textField的键盘属性来展示 self.textField.keyboardType = UIKeyboardTypeNum

简单自定义安全键盘(只能输入字母,数字,部分符号)

以前知道有个KeyboardView这个东西可以自定义键盘,但因为一直没涉及到,所以没研究过,今天看到工商银行密码输入的键盘觉得挺好看,就来研究一下. 先看一下工商银行的图 下边是我的效果图 参考了:http://blog.csdn.net/hfsu0419/article/details/7924673 http://www.cnblogs.com/jason-star/archive/2012/12/15/2819174.html 两篇博客. 现在做一下笔记. 在需要显示键盘的布局中,插入这