22 lines
705 B
JavaScript
22 lines
705 B
JavaScript
|
import Vue from 'vue';
|
|||
|
// 自定义指令,实现按下enter后,光标自动跳转下一个输入框
|
|||
|
Vue.directive('enterNextInput', {
|
|||
|
inserted: function (el) {
|
|||
|
el.addEventListener("keypress",function(e){
|
|||
|
e = e || window.event;
|
|||
|
let charcode = typeof e.charCode == 'number' ? e.charCode : e.keyCode;
|
|||
|
if(charcode == 13){
|
|||
|
var dom = document.querySelectorAll(".el-input__inner")
|
|||
|
for (var i = 0; i < dom.length; i++) {
|
|||
|
if (dom[i] == document.activeElement) {
|
|||
|
if (i==dom.length) {
|
|||
|
return
|
|||
|
}
|
|||
|
dom[i+1].focus()
|
|||
|
return
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
},
|
|||
|
});
|