javascript - 如何将焦点移动到Vuejs中的下一个输入字段?
问题描述
这是我的 codepen 链接https://codepen.io/santoshch/pen/LYxOoWO
我有 otp 字段,当所有 4 个字段时,如果我填写并按退格/删除按钮。然后只有它向后移动并删除输入的数字。
但是下面代码的问题是,当我在 otp 字段中输入单个数字并按退格/删除按钮时,它不会向后移动。(留在同一输入字段中)
// Shift focus to next input field if max length reached
if (value.length >= maxlength) {
if (typeof this.activationKeyFields[index + 1] == 'undefined') {
e.preventDefault();
return;
}
this.$refs[`input-${parseInt(index + 1)}`][0].focus();
e.preventDefault();
}
else{
if (typeof this.activationKeyFields[index - 1] == 'undefined') {
e.preventDefault();
return;
}
this.$refs[`input-${parseInt(index - 1)}`][0].focus();
e.preventDefault();
}
},
解决方案
推荐阅读
- python-3.x - 可以与整数比较的类
- laravel - 数据未提交到数据库
- automation - 如何在不使用 RQM 和 RQM 适配器的情况下在远程机器上运行 RFT 脚本?
- spring-boot - Spring Boot + Swagger-Ui yml 生成
- git - git add 多次而不提交
- python - 在python中对数据名称进行For循环
- kotlin - Kotlin 中的构造函数与参数
- c# - 在 EF Core 中禁用并发检查
- python-3.x - 有没有在 Julia 中使用 SQLAlchemy 的简单方法?
- elasticsearch - 用于百分位聚合值的 Elastic Search 存储桶脚本