功能型:js获取所有的input框元素 根据键盘上下方向键给某个input框加焦点事件

键盘事件监听 @keyup.native
@keyup.native="tdItem.onKeyUp($event, trItem, trIndex)"
               (item , row , index) 
  
.native在父组件中给子组件绑定一个原生的事件,就将子组件变成了普通的HTML标签
 
// 获取所有input
let inputAll = document.querySelectorAll('.table_input input');
// 向上键盘 =38
if (item.keyCode === 38) {
newIndex -= 1;
if (inputAll[newIndex]) {
inputAll[newIndex].focus();
}
}
// 向下键盘 =40
if (item.keyCode === 40) {
newIndex += 1;
if (inputAll[newIndex]) {
inputAll[newIndex].focus();
}
}
原文地址:https://www.cnblogs.com/wssdx/p/11122179.html