element table 實現input輸入框回車鍵跳入下一行,自動獲取焦點


element table 實現input輸入框回車鍵跳入下一行,自動獲取焦點

使用動態綁定ref  this.$refs獲取的是一個所有id組成的對象。

使用Object.keys(this.$refs) //遍歷這個對象,返回的是一個包含所有id組成的一個數組,讓當前的index+1獲取到下一個input的id.

再根據這個id 使用this.$refs獲取到這個input 使用focus

<template slot-scope="scope">
                <el-input
                  class="year-leiji"
                  :ref='scope.row.id'
                  autocomplete="off"
                  v-model.number="scope.row.ljje"
                  @keydown.native="validateCounts(scope.row,scope.$index, $event)"
                ></el-input>
              </template>

 

    validateCounts(row,index, e) {
      
      const val = e.target.value;
      var keyCode = e.keyCode || e.which || e.charCode;
      if(keyCode=== 13) {
        this.submitYearLeiJi(row.id, val)
        this.$refs[row.id].blur()
        if(Object.keys(this.$refs).length-1 === index) {
            index = -1
        }
        this.$refs[Object.keys(this.$refs)[index + 1]].focus();
      }
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM