vue實現(xiàn)輸入框自動跳轉(zhuǎn)功能
更新時間:2020年05月20日 14:26:37 作者:小二,來了
這篇文章主要為大家詳細介紹了vue實現(xiàn)輸入框自動跳轉(zhuǎn)功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了vue實現(xiàn)輸入框自動跳轉(zhuǎn)的具體代碼,供大家參考,具體內(nèi)容如下
<template>
<div class="inputClass">
<div v-for="(item,index) in list" :key="index">
<input v-model="item.value" type="password" class="inputBorder" @keyup="jumpNext($event,index,item.value)"
@keydown="replaceValue(index)">
</div>
</div>
</template>
JS:
jumpNext(event, index, val) {
if (!/[0-9]/.test(val)) {
this.list[index].value = "";
this.$message({
type: 'warning',
message: '該密碼僅為數(shù)字'
})
return
}
let flag = document.getElementsByClassName("inputBorder"),
currInput = flag[index],
nextInput = flag[index + 1],
lastInput = flag[index - 1];
if (event.keyCode != 8) {
if (index < (this.list.length - 1)) {
nextInput.focus();
} else {
currInput.blur();
}
} else {
if (index != 0) {
lastInput.focus();
}
}
if (index == 0) {
this.num1 = event.key + ''
} else if (index == 1) {
this.num2 = event.key + ''
} else if (index == 2) {
this.num3 = event.key + ''
} else if (index == 3) {
this.num4 = event.key + ''
} else if (index == 4) {
this.num5 = event.key + ''
} else if (index == 5) {
this.num6 = event.key + ''
}
let str = this.num1 + this.num2 + this.num3 + this.num4 + this.num5 + this.num6
if (str.length == 6) {
let params = str
setUpSVIP(params).then(res => {
// this.superVipVisible = false
}).catch(err => {
// this.superVipVisible = false
this.$message({
type: 'error',
message: '設(shè)置超級VIP失敗'
})
})
}
},
/*當(dāng)鍵盤按下的時候清空原有的數(shù)*/
replaceValue(index) {
this.list[index].value = "";
}
CSS:
.inputBorder {
background: #ffffff;
width: 50px;
font-size: 50px;
height: 50px;
margin-left: 0px;
margin-right: 0px;
text-align: center;
border: 1px solid #706969;
}
.inputClass {
margin-top: 31px;
display: flex;
justify-content: center;
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關(guān)文章
利用Vue3實現(xiàn)一個可以用js調(diào)用的組件
最近遇到個功能要求,想要在全局中調(diào)用組件,而且要在某些js文件內(nèi)調(diào)用,所以這篇文章主要給大家介紹了關(guān)于如何利用Vue3實現(xiàn)一個可以用js調(diào)用的組件的相關(guān)資料,需要的朋友可以參考下2021-08-08
vue3?reactive響應(yīng)式依賴收集派發(fā)更新原理解析
這篇文章主要為大家介紹了vue3響應(yīng)式reactive依賴收集派發(fā)更新原理解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-03-03
Message組件實現(xiàn)發(fā)財UI?示例詳解
這篇文章主要為大家介紹了Message組件實現(xiàn)發(fā)財UI的手寫示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-08-08

