vue+elementui 中 @keyup 键盘上下左右移动聚焦

摘要:
El table columnalalign=“center”label=“Normal”>El table columsign=“center”sortabprop=“normalB”label=“笔数”>El table columnalalign=“center”label=“Follow”>
            <template>
                  <el-table :data="CreditUnclearOutlineList" border style=" 100%" ref="table">
                                <el-table-column align="center" prop="name" label="名称" width="150">
                                </el-table-column>
                                <el-table-column align="center" label="正常">
                                    <el-table-column align="center" sortable prop="normalB" label="笔数">
                                        <template scope="scope">
                                            <span>
                                                <el-input style=" 90px" placeholder="笔数" v-model="scope.row.normalB" @change="handleCreditChange()" class="table_input normalB_input" @keyup.native="show($event,scope.$index)"></el-input>
                                            </span>
                                        </template>
                                    </el-table-column>
                                    <el-table-column align="center" sortable prop="normalY" label="余额(万元)">
                                        <template scope="scope">
                                            <span>
                                                <el-input style=" 90px" placeholder="余额" v-model="scope.row.normalY" @change="handleCreditChange()" @blur="handleBalanceBlur($event)" @focus="handleBalanceClear($event)" class="table_input normalY_input" @keyup.native="show($event,scope.$index)"></el-input>
                                            </span>
                                        </template>
                                    </el-table-column>
                                </el-table-column>
                                <el-table-column align="center" label="关注">
                                    <el-table-column align="center" sortable prop="focusB" label="笔数">
                                        <template scope="scope">
                                            <span>
                                                <el-input style=" 90px" placeholder="笔数" v-model="scope.row.focusB" @change="handleCreditChange()" class="table_input focusB_input" @keyup.native="show($event,scope.$index)"></el-input>
                                            </span>
                                        </template>
                                    </el-table-column>
                                    <el-table-column align="center" sortable prop="focusY" label="余额(万元)">
                                        <template scope="scope">
                                            <span>
                                                <el-input style=" 90px" placeholder="余额" v-model="scope.row.focusY" @change="handleCreditChange()" @blur="handleBalanceBlur($event)" @focus="handleBalanceClear($event)" class="table_input focusY_input" @keyup.native="show($event,scope.$index)"></el-input>
                                            </span>
                                        </template>
                                    </el-table-column>
                                </el-table-column>
                                <el-table-column align="center" label="不良">
                                    <el-table-column align="center" sortable prop="badB" label="笔数">
                                        <template scope="scope">
                                            <span>
                                                <el-input style=" 90px" placeholder="笔数" v-model="scope.row.badB" @change="handleCreditChange()" class="table_input badB_input" @keyup.native="show($event,scope.$index)"></el-input>
                                            </span>
                                        </template>
                                    </el-table-column>
                                    <el-table-column align="center" sortable prop="badY" label="余额(万元)">
                                        <template scope="scope">
                                            <span>
                                                <el-input style=" 90px" placeholder="余额" v-model="scope.row.badY" @change="handleCreditChange()" @blur="handleBalanceBlur($event)" @focus="handleBalanceClear($event)" class="table_input badY_input" @keyup.native="show($event,scope.$index)"></el-input>
                                            </span>
                                        </template>
                                    </el-table-column>
                                </el-table-column>
                                <el-table-column align="center" prop="amountY" sortable label="余额(万元)">
                                    <template scope="scope">
                                        <span>{{scope.row.amountY}}</span>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </template>
//键盘触发事件
show(ev,index){ let newIndex ;
//通过ev 获取 当前input 名称 用于判断属于哪列 let clssName = ev.target.offsetParent.className; //每一列 if(clssName.indexOf('normalB_input') != -1){ newIndex = index*6 ; } else if (clssName.indexOf('normalY_input') != -1) { newIndex = index*6 + 1 ; } else if (clssName.indexOf('focusB_input') != -1) { newIndex = index*6 + 2; } else if (clssName.indexOf('focusY_input') != -1) { newIndex = index*6 + 3; } else if (clssName.indexOf('badB_input') != -1) { newIndex = index*6 + 4; } else if (clssName.indexOf('badY_input') != -1) { newIndex = index*6 + 5; } //获取每一列的input名称 let normalB_input = document.getElementsByClassName('normalB_input') let normalY_input = document.getElementsByClassName('normalY_input') let focusB_input = document.getElementsByClassName('focusB_input') let focusY_input = document.getElementsByClassName('focusY_input') let badB_input = document.getElementsByClassName('badB_input') let badY_input = document.getElementsByClassName('badY_input') //获取54个input let inputAll = document.querySelectorAll('.table_input input'); //向上 =38 if(ev.keyCode == 38){ //当焦点在第一行的时候 按向上的时候焦点要聚焦到前一列的最后一个 if(newIndex >=1 && newIndex<=5){ newIndex = newIndex + 47; } else { newIndex -= 6 ; } if( inputAll[newIndex] ){ inputAll[newIndex].focus(); } } //下 = 40 if(ev.keyCode == 40){ //当newIndex 在最后一行的时候 焦点要聚焦到 下一列的第一个 if(newIndex>= 48 && newIndex<53){ newIndex = (newIndex%8) + 1 }else { newIndex += 6 ; } if( inputAll[newIndex] ){ inputAll[newIndex].focus(); } } //左 = 37 if(ev.keyCode == 37){ newIndex -= 1 ; if( inputAll[newIndex] ){ inputAll[newIndex].focus(); } } //右 = 39 if(ev.keyCode == 39){ newIndex += 1 ; if( inputAll[newIndex] ){ inputAll[newIndex].focus(); } } },

注意点: 

1.vue element-ui 绑定@keyup事件无效 ,加上.native覆盖原有封装的keyup事件即可

免责声明:文章转载自《vue+elementui 中 @keyup 键盘上下左右移动聚焦》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇红点系统设计思路URL编码与解码下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

微信 ios端config配置失败 android端正常

<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script> 如果你页面启用了https,务必引入 https://res.wx.qq.com/open/js/jweixin-1.0.0.js ,否则将无法在iOS9.0以上系统中成功使用JSSDK...

基于SpringBoot 、AOP与自定义注解转义字典值

  一直以来,前端展示字典一般以中文展示为主,若在表中存字典值中文,当字典表更改字典值对应的中文,会造成数据不一致,为此设置冗余字段并非最优方案,若由前端自己写死转义,不够灵活,若在业务代码转义,臃肿也不够通用,从网络上了解到注解、AOP是一种不错的解决方案,主要有两种方式:   1、通过注解获取结果集转为JSON字符串,通过正则查找附加字段;   2、通...

eventlet的学习

转自:http://bingotree.cn/?p=281 官方网站:http://eventlet.net/ 之前小秦我写了篇python中协程和yield的文章,这里小秦我再总结一下eventlet中比较重要的几个知识点。 1.安装方法: 1 [root@COMPUTE02 ~]# pip install eventlet 2.基础知识及优点 ev...

selenium实现淘宝的商品爬取

一、问题 本次利用selenium自动化测试,完成对淘宝的爬取,这样可以避免一些反爬的措施,也是一种爬虫常用的手段。本次实战的难点: 1.如何利用selenium绕过淘宝的登录界面 2.获取淘宝的页面内容实现翻页,并判断是否翻页成功。 3.获取每一页的信息,实现数据的抓取工作。  4.环境python3.6,对应的Chrome的webdriver驱动网址:...

命令行创建快捷方式的批处理脚本

    从网上搜集了一些“创建快捷方式”的批处理脚本,以供将来工作中参考: 一、示例为创建记事本的快捷方式到桌面 set path=%WINDIR%\notepad.exe set topath="%USERPROFILE%\桌面\记事本.url" echo [InternetShortcut] >> %topath% echo URL="%p...

vue可调整大小和可拖动的组件---vue-draggable-resizable

vue-draggable-resizable 用于可调整大小和可拖动元素的组件、并支持组件之间的冲突检测和组件对齐。 使用流程: 安装依赖: npm install --save vue-draggable-resizable 注册组件(在main.js中添加下列代码): import Vue from 'vue' import VueDraggabl...