jq文本框自动跳转下一个(输入密码)jsdemo效果示例(整理)
2023-09-14 09:04:05 时间
<!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>
相关文章
- bcrypt加密password BCrypt对密码进行加密及密码验证
- idea中git git pull push需要反复输入密码
- MySQL修改root密码的多种方法
- js中利用cookie实现记住密码功能
- 生活娱乐 ATM机键盘余温泄露密码
- PostgreSQL 自动输入密码(转)
- Ubuntu执行su后输入密码结果认证失败--解决办法:sudo passwd修改命令
- 详细说明 linux sudo 不要密码
- 采用Cloudera-Manager安装CDH时,采用内嵌数据库各数据库用户密码的保存位置
- mac无法访问samba共享 提示输入用户名密码
- python自定义小工具:密码匿名化、毫秒时间显示、人类易读字节
- Python语言学习:Python语言学习之编程语言基础案例综合应用集合(输入带*号的密码/与用户交/根据分数判断优良差/提取txt文档中两人对话内容等)之详细攻略
- Linux从零开始(二、基础命令(续三)修改密码)
- Android 9.0 app添加校验锁(输入密码才能进入app)
- 【华为OD机试 2023】 最长的密码(C++ Java JavaScript Python)
- VScode将代码提交到远程服务器、同时解决每次提交都要输入密码的问题(这里以gitee为例子)
- 使scp不用输入密码
- mysql输入密码后闪退怎么办?
- ssh 输入密码后欢迎信息设置
- 不改动当前账户密码的情况下,启用其他账户登录windows系统
- sudo -i 不需要输入密码
- ssh免密码登陆远程服务器三种方式(三)
- git pull 总要求输入账号和密码解决?
- Android中EditText显示明文与密码的两种方式
- 笔记本开机后显示不了输入密码界面
- Win10 开机输入密码后登入桌面就黑屏,只有鼠标可以移动, 打不开任务管理器,不用重装系统怎么修复?(已解决)十四个解决参考方案
- Win10开机输入密码后1分钟左右就蓝屏,一天出现10个不同蓝屏代码,如何解决
- MacBook Air怎么重新输入wifi密码
- 【C#】远程桌面(mstsc.exe)带IP地址/端口/用户名/密码等参数实现无需输入密码而自动登录