键盘事件

2021-01-14  本文已影响0人  一枚小菜
        .setpsw {
            margin: 0 auto;
            height: 50px;
            overflow: hidden;
            display: inline-block;
        }

        .setpsw input {
            width: 30px;
            height: 30px;
            padding: 0 0;
            float: left;
            margin: 5px;
            text-align: center;
            line-height: 21px;
            border: 1px solid rgba(0, 0, 0, .2);
            border-radius: 3px;
            outline: 0;
            background-color: #fff;
        }
    </style>
 <div class="setpsw input">
        <input type="password">
        <input type="password">
        <input type="password">
        <input type="password">
        <input type="password">
        <input type="password">
    </div>
<script>
  $(".input input").keyup(function (event) {
            var e = (event) ? event : window.event;
            if ((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 96 && e.keyCode <= 105)) {
                var value = $(this).val();
                var length = value.length;
                var val;
                if (length > 0.5) {
                    val = value.substring(length - 1, length);
                    $(this).val(val).next().focus()
                }
            } else if (e.keyCode == 8) {
                $(this).prev().focus()
            } else {
                var _val = this.value;
                this.value = _val.replace(/\D/g, '');
            }
        });
</script>
输入6位数字密码

显示输入字数及提示

    function(){
        var count=$(this).val().length;
        $("#textcount").html(count);
        if(count>70){
            $("#tip").show();
        }else{
            $("#tip").hide();
        }
    }
)
上一篇 下一篇

猜你喜欢

热点阅读