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