erp-el-element/utils/directive.js

22 lines
705 B
JavaScript
Raw Normal View History

2024-05-07 11:51:58 +08:00
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
}
}
}
});
},
});