功能型: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();
}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM