• 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{ 200px; margin:0 auto}
    11 .num{ 200px;height: 30px; line-height:30px; border: 1px solid #666;}
    12 .num span{position: relative;display: inline-block; min- 1px; height: 30px;}
    13 .num.active span:after{content: ''; position: absolute; right: -2px; top: 4px; height: 20px;  1px; background: #000; animation: 1s linear infinite blink; -webkit-animation: 1s linear infinite blink;}
    14 @keyframes blink{
    15     0%{
    16          1px;
    17     }
    18     49.9999%{
    19          1px;
    20     }
    21     50%{
    22          0;
    23     }
    24     100%{
    25          0;
    26     }
    27 }
    28 @-webkit-keyframes blink{
    29     0%{
    30          1px;
    31     }
    32     49.9999%{
    33          1px;
    34     }
    35     50%{
    36          0;
    37     }
    38     100%{
    39          0;
    40     }
    41 }
    42 .key{ display: none;height: 120px;  250px; position: absolute;left:60px;bottom:50px;}
    43 .kc{ 160px;float: left;}
    44 .key span{float: left;  30px;height: 30px; margin:10px 10px 0 10px; line-height:30px;text-align: center;border: 1px solid #666;}
    45 .key em{ 80px;float: left;}
    46 .key em i{display: block; 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>
  • 相关阅读:
    PAT Advanced 1138 Postorder Traversal (25) [树的遍历,前序中序转后序]
    PAT Advanced 1127 ZigZagging on a Tree (30) [中序后序建树,层序遍历]
    PAT Advanced 1020 Tree Traversals (25) [⼆叉树的遍历,后序中序转层序]
    PAT Basic 1075 链表元素分类(25) [链表]
    PAT A1133 Splitting A Linked List (25) [链表]
    PAT Advanced 1097 Deduplication on a Linked List (25) [链表]
    PAT Basic 反转链表 (25) [链表]
    PAT Advanced 1074 Reversing Linked List (25) [链表]
    PAT Advanced 1052 Linked List Sorting (25) [链表]
    PAT Advanced 1032 Sharing(25) [链表]
  • 原文地址:https://www.cnblogs.com/axl234/p/6845500.html
Copyright © 2020-2023  润新知