vue+el-table可输入表格使用上下键进行input框切换方式

 更新时间:2025年11月03日 09:30:31   作者:以对_  
文章介绍了如何在使用Vue和Element UI的el-table组件时,通过上下键在输入框之间切换,并且特别说明了如何在完工数量这一列中使用上下键进行切换

vue+el-table可输入表格使用上下键进行input框切换

使用上下键进行完工数量这一列的切换

<el-table :data="form.detailList" @selection-change="handleChildSelection" ref="bChangeOrderChild" max-height="500">
 <!-- <el-table-column type="selection" width="50" align="center"/> -->
 <el-table-column label="序号" align="center" prop="index" width="50"/>

 <el-table-column label="产品名称">
   <template slot-scope="scope">
     <el-input v-model="scope.row.materialName" readonly/>
   </template>
 </el-table-column>
 <el-table-column label="完工数量" prop="wrastNum">
   <template slot-scope="scope">
     <el-input v-model="scope.row.wrastNum" placeholder="请输入完工数量" @focus="wrastNumFocus(scope.row)" @keyup.native="show($event,scope.$index)" class="table_input badY_input"/>
   </template>
 </el-table-column>
 <el-table-column label="入库批次号" prop="productBatchNum">
   <template slot-scope="scope">
     <el-input v-model="scope.row.productBatchNum" placeholder="请输入入库批次号" />
   </template>
 </el-table-column>
 <el-table-column label="开始时间" prop="planStartTime" width="230">
   <template slot-scope="scope">
     <el-date-picker clearable
       style="width: 100%;"
       v-model="scope.row.planStartTime"
       type="datetime"
       value-format="yyyy-MM-dd HH:mm:ss"
       placeholder="请选择开始时间">
     </el-date-picker>
   </template>
 </el-table-column>
 <el-table-column label="结束时间" prop="planEndTime" width="230">
   <template slot-scope="scope">
     <el-date-picker clearable
       style="width: 100%;"
       v-model="scope.row.planEndTime"
       type="datetime"
       value-format="yyyy-MM-dd HH:mm:ss"
       placeholder="请选择结束时间">
     </el-date-picker>
   </template>
 </el-table-column>
 <el-table-column label="备注" prop="note">
   <template slot-scope="scope">
     <el-input v-model="scope.row.note" placeholder="请输入备注" />
   </template>
 </el-table-column>
</el-table>
//键盘触发事件
show(ev,index){
  let newIndex;
  let inputAll = document.querySelectorAll('.table_input input');

  //向上 =38
  if (ev.keyCode == 38) {

    if( index==0 ) {// 如果是第一行,回到最后一个
      newIndex = inputAll.length - 1
    }else if( index == inputAll.length ) {// 如果是最后一行,继续向上
      newIndex = index - 1
    }else if( index > 0 && index < inputAll.length ) {// 如果是中间行,继续向上
      newIndex = index - 1
    }

    if (inputAll[newIndex]) {
      inputAll[newIndex].focus();
    }
  }

  //下 = 40
  if (ev.keyCode == 40) {

    if( index==0 ) {// 如果是第一行,继续向下
      newIndex = index+1
    }else if( index == inputAll.length-1 ) {// 如果是最后一行,回到第一个
      newIndex = 0
    }else if( index > 0 && index < inputAll.length ) {// 如果是中间行,继续向下
      newIndex = index + 1
    }

    if (inputAll[newIndex]) {
      inputAll[newIndex].focus();
    }
  }
}

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • 解决vue3中内存泄漏的问题

    解决vue3中内存泄漏的问题

    在项目中会发现一个奇怪的现象,当我们在使用element-plus中的图标组件时会出现内存泄漏,所以本文讲给大家讲讲如何解决vue3中的内存泄漏的问题,需要的朋友可以参考下
    2023-07-07
  • Vue3实现动态高度的虚拟滚动列表的示例代码

    Vue3实现动态高度的虚拟滚动列表的示例代码

    虚拟滚动列表是一种优化长列表渲染性能的技术,通过只渲染可视区域内的列表项,减少DOM的渲染数量,本文就来介绍一下Vue3实现动态高度的虚拟滚动列表的示例代码,具有一定的参考价值,感兴趣的可以了解一下
    2025-01-01
  • vue3组合式API实现todo列表效果

    vue3组合式API实现todo列表效果

    这篇文章主要介绍了vue3组合式API实现todo列表,下面用组合式 API的写法,实现一个可新增、删除的todo列表效果,需要的朋友可以参考下
    2024-08-08
  • vue定义私有过滤器和基本使用

    vue定义私有过滤器和基本使用

    这篇文章主要介绍的是 vue定义私有过滤器和基本使用,下面文章围绕vue定义私有过滤器的相关资料展开内容,需要的朋友可以参考一下,希望对大家有所帮助
    2021-11-11
  • 如何解决前端上传Formdata中的file为[object Object]的问题

    如何解决前端上传Formdata中的file为[object Object]的问题

    文件上传是Web开发中常见的功能之一,下面这篇文章主要给大家介绍了关于如何解决前端上传Formdata中的file为[object Object]问题的相关资料,文中通过代码介绍的非常详细,需要的朋友可以参考下
    2024-07-07
  • vue判断input输入内容全是空格的方法

    vue判断input输入内容全是空格的方法

    下面小编就为大家分享一篇vue判断input输入内容全是空格的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2018-03-03
  • vue项目中的数据变化被watch监听并处理

    vue项目中的数据变化被watch监听并处理

    这篇文章主要介绍了vue项目中的数据变化被watch监听并处理,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-04-04
  • vite打包出现 "default" is not exported by "node_modules/...问题解决办法

    vite打包出现 "default" is not exported by "

    这篇文章主要给大家介绍了关于vite打包出现 "default" is not exported by "node_modules/...问题的解决办法,文中通过代码将解决的办法介绍的非常详细,对同样遇到这个问题的朋友具有一定的参考借鉴价值,需要的朋友可以参考下
    2024-06-06
  • 利用vueJs实现图片轮播实例代码

    利用vueJs实现图片轮播实例代码

    本篇文章主要介绍了利用vueJs实现图片轮播实例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-06-06
  • vue项目打包优化的方法实战记录

    vue项目打包优化的方法实战记录

    最近入职了新公司,接手了一个新拆分出来的Vue项目,针对该项目做了个打包优化,把经验分享出来,下面这篇文章主要给大家介绍了关于vue项目打包优化的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
    2022-08-08

最新评论