jq文本框自动跳转下一个(输入密码)jsdemo效果示例(整理)

简介: jq文本框自动跳转下一个(输入密码)jsdemo效果示例(整理)
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>文本框自动跳转下一个</title>
    <script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
    <style>
      .input {
        display: block;
        width: 40px;
        height: 35px;
        float: left;
        margin-left: 10px;
        text-align: center;
      }
    </style>
  </head>
  <body>
    <div id="body">
          <input type="text" maxlength="1" class="input">
          <input type="text" maxlength="1" class="input">
          <input type="text" maxlength="1" class="input">
          <input type="text" maxlength="1" class="input">
          <input type="text" maxlength="1" class="input">
          <input type="text" maxlength="1" class="input">
    </div>
    <script>
      $(function() {
        var inputLength = $('input').length;
        //$('input').keyup(function(){})
        //使用jQuery事件代理的事件绑定方式,不需要对每个input进行事件绑定,有利于性能优化
        $('#body').delegate('input', 'keyup', function() {
          var _this = $(this),
            valLength = _this.val().length,
            index = _this.index();
          if (valLength > 0) {
            if ((index + 1) > inputLength) return false; //输入完成时进行操作
            _this.attr('data-in', 'true').next().focus();
          } else if (valLength == 0 && _this.attr('data-in') == 'true') {
            if (index == 0) return false; //删除所有时进行操作
            _this.attr('data-in', 'false').prev().focus();
          }
        });
      });
    </script>
  </body>
</html>

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>验证码输入框</title>
    <script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
    <style>
      input {
        width: 40px;
        height: 40px;
        text-align: center;
        font-size: 20px;
      }
    </style>
  </head>
  <body>
    <div id="ipt">
          <input type="text">
          <input type="text">
          <input type="text">
          <input type="text">
          <input type="text">
          <input type="text">
    </div>
    <script>
      $('#ipt input:gt(0)').attr('readOnly', 'true');
      $('#ipt input').keyup(function() {
        if (/^[0-9]{1}$/g.test($(this).val())) {
          $(this).next().removeAttr('readOnly').focus();
        } else {
          alert('请输入1位数字');
          $(this).val('');
        }
      });
    </script>
  </body>
</html>


目录
打赏
0
0
0
0
12
分享
相关文章
在某网站的登录页面登录时如果选择“记住用户名”,登录成功后会跳转到一个中间层(页面代码将登录的用户名和密码存在cookie),中间页面中存在一个超链接,单击超链接可以链接到第三个页面查看信息。若选择“
该博客文章通过示例代码和运行结果截图,展示了网站登录过程中如何通过中间层页面使用cookies技术实现“记住用户名”功能,并在点击超链接后查看保存的用户名和密码信息。
在某网站的登录页面登录时如果选择“记住用户名”,登录成功后会跳转到一个中间层(页面代码将登录的用户名和密码存在cookie),中间页面中存在一个超链接,单击超链接可以链接到第三个页面查看信息。若选择“
|
7月前
|
点击输入框,获取提示信息
点击输入框,获取提示信息
38 1
vue编写一个登录页面,使用Tab栏实现“账号登录”和“二维码登录”这两种方式的切换
vue编写一个登录页面,使用Tab栏实现“账号登录”和“二维码登录”这两种方式的切换
1199 2
vue编写一个登录页面,使用Tab栏实现“账号登录”和“二维码登录”这两种方式的切换
jq点击导航页面滑动到对应内容demo效果示例(整理)
jq点击导航页面滑动到对应内容demo效果示例(整理)
点击回车,完成登录功能
点击回车,完成登录功能
118 0
jq修改页面中的图片地址
jq修改页面中的图片地址
175 0
从页面输入网址,回车到显示内容,这中间到底经历了什么
阿粉在学习计算机网络的内容时,脑子里面突然冒出来一个问题:当我们在一个浏览器界面输入网址,回车到界面显示内容,这中间经历了什么?
从页面输入网址,回车到显示内容,这中间到底经历了什么
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等