vue+el-table可輸入表格使用上下鍵進(jìn)行input框切換方式
更新時(shí)間:2025年11月03日 09:30:31 作者:以對(duì)_
文章介紹了如何在使用Vue和Element UI的el-table組件時(shí),通過(guò)上下鍵在輸入框之間切換,并且特別說(shuō)明了如何在完工數(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="入庫(kù)批次號(hào)" prop="productBatchNum">
<template slot-scope="scope">
<el-input v-model="scope.row.productBatchNum" placeholder="請(qǐng)輸入入庫(kù)批次號(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)文章
Vue3實(shí)現(xiàn)動(dòng)態(tài)高度的虛擬滾動(dòng)列表的示例代碼
虛擬滾動(dòng)列表是一種優(yōu)化長(zhǎng)列表渲染性能的技術(shù),通過(guò)只渲染可視區(qū)域內(nèi)的列表項(xiàng),減少DOM的渲染數(shù)量,本文就來(lái)介紹一下Vue3實(shí)現(xiàn)動(dòng)態(tài)高度的虛擬滾動(dòng)列表的示例代碼,具有一定的參考價(jià)值,感興趣的可以了解一下2025-01-01
vue3組合式API實(shí)現(xiàn)todo列表效果
這篇文章主要介紹了vue3組合式API實(shí)現(xiàn)todo列表,下面用組合式?API的寫法,實(shí)現(xiàn)一個(gè)可新增、刪除的todo列表效果,需要的朋友可以參考下2024-08-08
如何解決前端上傳Formdata中的file為[object?Object]的問(wèn)題
文件上傳是Web開發(fā)中常見的功能之一,下面這篇文章主要給大家介紹了關(guān)于如何解決前端上傳Formdata中的file為[object?Object]問(wèn)題的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-07-07
vue項(xiàng)目中的數(shù)據(jù)變化被watch監(jiān)聽并處理
這篇文章主要介紹了vue項(xiàng)目中的數(shù)據(jù)變化被watch監(jiān)聽并處理,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04
vite打包出現(xiàn)?"default"?is?not?exported?by?"
這篇文章主要給大家介紹了關(guān)于vite打包出現(xiàn)?"default"?is?not?exported?by?"node_modules/...問(wèn)題的解決辦法,文中通過(guò)代碼將解決的辦法介紹的非常詳細(xì),對(duì)同樣遇到這個(gè)問(wèn)題的朋友具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2024-06-06
利用vueJs實(shí)現(xiàn)圖片輪播實(shí)例代碼
本篇文章主要介紹了利用vueJs實(shí)現(xiàn)圖片輪播實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-06-06
vue項(xiàng)目打包優(yōu)化的方法實(shí)戰(zhàn)記錄
最近入職了新公司,接手了一個(gè)新拆分出來(lái)的Vue項(xiàng)目,針對(duì)該項(xiàng)目做了個(gè)打包優(yōu)化,把經(jīng)驗(yàn)分享出來(lái),下面這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目打包優(yōu)化的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08

