zoukankan      html  css  js  c++  java
  • 验证码输入自动聚焦下一个input或者删除自动聚焦上一个input

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>验证码输入自动聚焦下一个input或者删除自动聚焦上一个input</title>
    </head>
    <style type="text/css">
        body{
            background-color: #E6E6FA;
        }
        .center{
            display: flex;
             400px;
            height: 400px;
            margin: 0 auto;
        }
        input{
            flex: 1;
            height: 100px;
            font-size: 40px;
            text-align: center;
        }
        .now{
            70px;
            heigth:70px;
            border:1px #cccccc solid;
        }
        .now:focus{
            border:1px #587d18 solid;
        }   
    </style>
    <body>
    <img src='验证码地址'>
    <div class="center">
        <input type='text' name='code[]' class='now' maxlength="1"/>
        <input type='text' name='code[]' class='now' maxlength="1"/>
        <input type='text' name='code[]' class='now' maxlength="1"/>
        <input type='text' name='code[]' class='now' maxlength="1"/>
    </div>
    
    <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
    <script type="text/javascript">
       /* $('.now').keyup(function(){
        if($(this).index()<4) {
            $(this).next('input').focus();
        }
    });
    */
    
    $("input[name^='code']").each(function(){
        $(this).keyup(function(e){
            if($(this).val().length < 1){
                $(this).prev().focus();
            }else{
                if($(this).val().length >= 1){
                    $(this).next().focus();
                }
            }
        });
        
    });
    
    </script>
    </body>
    
    </html>
    

      

  • 相关阅读:
    Kafka 核心 API ==> AdminClient
    Kafka ==> 简介
    设计模式之 ==> 代理设计模式
    设计模式之 ==> 工厂设计模式
    设计模式之 ==> 模板设计模式
    设计模式之 ==> 单例模式
    Linux目录【持续更新中】
    Python 目录【持续更新中】
    kafka-eagle部署
    ES集群部署
  • 原文地址:https://www.cnblogs.com/zxcc/p/11321538.html
Copyright © 2011-2022 走看看