功能型: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