vue+el-table可輸入表格使用上下鍵進(jìn)行input框切換方式
更新時(shí)間:2025年11月03日 09:30:31 作者:以對(duì)_
文章介紹了如何在使用Vue和Element UI的el-table組件時(shí),通過上下鍵在輸入框之間切換,并且特別說明了如何在完工數(shù)量這一列中使用上下鍵進(jìn)行切換
vue+el-table可輸入表格使用上下鍵進(jìn)行input框切換

使用上下鍵進(jìn)行完工數(shù)量這一列的切換
<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="序號(hào)" align="center" prop="index" width="50"/>
<el-table-column label="產(chǎn)品名稱">
<template slot-scope="scope">
<el-input v-model="scope.row.materialName" readonly/>
</template>
</el-table-column>
<el-table-column label="完工數(shù)量" prop="wrastNum">
<template slot-scope="scope">
<el-input v-model="scope.row.wrastNum" placeholder="請(qǐng)輸入完工數(shù)量" @focus="wrastNumFocus(scope.row)" @keyup.native="show($event,scope.$index)" class="table_input badY_input"/>
</template>
</el-table-column>
<el-table-column label="入庫批次號(hào)" prop="productBatchNum">
<template slot-scope="scope">
<el-input v-model="scope.row.productBatchNum" placeholder="請(qǐng)輸入入庫批次號(hào)" />
</template>
</el-table-column>
<el-table-column label="開始時(shí)間" 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="請(qǐng)選擇開始時(shí)間">
</el-date-picker>
</template>
</el-table-column>
<el-table-column label="結(jié)束時(shí)間" 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="請(qǐng)選擇結(jié)束時(shí)間">
</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="請(qǐng)輸入備注" />
</template>
</el-table-column>
</el-table>
//鍵盤觸發(fā)事件
show(ev,index){
let newIndex;
let inputAll = document.querySelectorAll('.table_input input');
//向上 =38
if (ev.keyCode == 38) {
if( index==0 ) {// 如果是第一行,回到最后一個(gè)
newIndex = inputAll.length - 1
}else if( index == inputAll.length ) {// 如果是最后一行,繼續(xù)向上
newIndex = index - 1
}else if( index > 0 && index < inputAll.length ) {// 如果是中間行,繼續(xù)向上
newIndex = index - 1
}
if (inputAll[newIndex]) {
inputAll[newIndex].focus();
}
}
//下 = 40
if (ev.keyCode == 40) {
if( index==0 ) {// 如果是第一行,繼續(xù)向下
newIndex = index+1
}else if( index == inputAll.length-1 ) {// 如果是最后一行,回到第一個(gè)
newIndex = 0
}else if( index > 0 && index < inputAll.length ) {// 如果是中間行,繼續(xù)向下
newIndex = index + 1
}
if (inputAll[newIndex]) {
inputAll[newIndex].focus();
}
}
}
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
使用md5在vue中的axios請(qǐng)求時(shí)加密API問題
這篇文章主要介紹了使用md5在vue中的axios請(qǐng)求時(shí)加密API問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01
Vue3中的toRef和toRefs的區(qū)別和用法示例小結(jié)
toRef和toRefs可以用來復(fù)制reactive里面的屬性然后轉(zhuǎn)成 ref,它保留了響應(yīng)式,也保留了引用,也就是你從 reactive 復(fù)制過來的屬性進(jìn)行修改后,除了視圖會(huì)更新,原有 ractive 里面對(duì)應(yīng)的值也會(huì)跟著更新,本文介紹Vue3中toRef和toRefs的區(qū)別和用法,需要的朋友可以參考下2024-08-08
深入詳解Vue3實(shí)現(xiàn)多環(huán)境配置與切換方式
這篇文章主要為大家詳細(xì)介紹了Vue3中實(shí)現(xiàn)多環(huán)境配置與切換方式的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2025-09-09
Vue-resource攔截器判斷token失效跳轉(zhuǎn)的實(shí)例
下面小編就為大家?guī)硪黄猇ue-resource攔截器判斷token失效跳轉(zhuǎn)的實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-10-10
基于Vue實(shí)現(xiàn)tab欄切換內(nèi)容不斷實(shí)時(shí)刷新數(shù)據(jù)功能
在項(xiàng)目開發(fā)中遇到這樣需求,就是有幾個(gè)tab欄,每個(gè)tab欄對(duì)應(yīng)的ajax請(qǐng)求不一樣,內(nèi)容區(qū)域一樣,內(nèi)容為實(shí)時(shí)刷新數(shù)據(jù),實(shí)現(xiàn)方法其實(shí)很簡(jiǎn)單的,下面小編給大家?guī)砹嘶赩ue實(shí)現(xiàn)tab欄切換內(nèi)容不斷實(shí)時(shí)刷新數(shù)據(jù)功能,需要的朋友參考下吧2017-04-04
vue的ElementUI form表單如何給label屬性字符串中添加空白占位符
這篇文章主要介紹了vue的ElementUI form表單如何給label屬性字符串中添加空白占位符問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10
vue2.0 兄弟組件(平級(jí))通訊的實(shí)現(xiàn)代碼
這篇文章主要介紹了vue2.0 兄弟組件(平級(jí))通訊的實(shí)現(xiàn)代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2018-01-01

