功能需求:做一个身份证后四位输入或汽车牌照输入,每个数字/字母一个input
,想输入完当前的input
后自动跳到下一个input
,删除当前input
后自动跳到前一个。
1、template代码
<div v-for="(item, index) in inputList" :key="index">
<input
type="text"
v-model="item.val"
class="inputValue"
@keyup="inputNextFocus($event, index)"
@keydown="cancelValue(index)"
/>
</div>
//注意:inputValue
2、script代码
data() {
return {
inputList: [{ val: "" }, { val: "" }, { val: "" }, { val: "" }], //根据个数
}
}
methods: {
inputNextFocus(el, index) {
var dom = document.getElementsByClassName("inputValue"), //引入inputValue
currInput = dom[index],
nextInput = dom[index + 1],
lastInput = dom[index - 1];
if (el.keyCode != 8) {
if (index < this.inputList.length - 1) {
nextInput.focus();
} else {
currInput.blur();
}
} else {
if (index != 0) {
lastInput.focus();
}
}
},
cancelValue(index) {
this.inputList[index].val = "";
}
}
以上是编程学习网小编为您介绍的“vuejs实现输入完input自动跳到下一个input”的全面内容,想了解更多关于 vuejs 内容,请继续关注编程基础学习网。
织梦狗教程
本文标题为:vuejs实现输入完input自动跳到下一个input


基础教程推荐
猜你喜欢
- 不使用XMLHttpRequest对象实现Ajax效果的方法小结 2023-02-23
- 基于ajax的简单搜索实现方法 2022-10-18
- 页面图片浮动左右滑动效果的简单实现案例 2024-01-23
- CSS 清除浮动元素方法 整理 2024-03-10
- vue3如何解决store.state.count错误的取值 2025-01-12
- 学习从实践开始之jQuery插件开发 对话框插件开发 2024-02-05
- javascript中bind函数的作用实例介绍 2023-12-01
- Vue3怎么运用pinia状态管理工具 2025-01-13
- 如何在JavaScript中使用localStorage详情 2024-02-12
- js中cookie的添加、取值、删除示例代码 2024-01-29