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

使用上下鍵進行完工數(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="序號" 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="請輸入完工數(shù)量" @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="結(jié)束時間" 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="請選擇結(jié)束時間">
</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>
//鍵盤觸發(fā)事件
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 ) {// 如果是最后一行,繼續(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 ) {// 如果是最后一行,回到第一個
newIndex = 0
}else if( index > 0 && index < inputAll.length ) {// 如果是中間行,繼續(xù)向下
newIndex = index + 1
}
if (inputAll[newIndex]) {
inputAll[newIndex].focus();
}
}
}
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue3中的toRef和toRefs的區(qū)別和用法示例小結(jié)
toRef和toRefs可以用來復(fù)制reactive里面的屬性然后轉(zhuǎn)成 ref,它保留了響應(yīng)式,也保留了引用,也就是你從 reactive 復(fù)制過來的屬性進行修改后,除了視圖會更新,原有 ractive 里面對應(yīng)的值也會跟著更新,本文介紹Vue3中toRef和toRefs的區(qū)別和用法,需要的朋友可以參考下2024-08-08
深入詳解Vue3實現(xiàn)多環(huán)境配置與切換方式
這篇文章主要為大家詳細介紹了Vue3中實現(xiàn)多環(huán)境配置與切換方式的相關(guān)知識,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2025-09-09
Vue-resource攔截器判斷token失效跳轉(zhuǎn)的實例
下面小編就為大家?guī)硪黄猇ue-resource攔截器判斷token失效跳轉(zhuǎn)的實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-10-10
基于Vue實現(xiàn)tab欄切換內(nèi)容不斷實時刷新數(shù)據(jù)功能
在項目開發(fā)中遇到這樣需求,就是有幾個tab欄,每個tab欄對應(yīng)的ajax請求不一樣,內(nèi)容區(qū)域一樣,內(nèi)容為實時刷新數(shù)據(jù),實現(xiàn)方法其實很簡單的,下面小編給大家?guī)砹嘶赩ue實現(xiàn)tab欄切換內(nèi)容不斷實時刷新數(shù)據(jù)功能,需要的朋友參考下吧2017-04-04
vue的ElementUI form表單如何給label屬性字符串中添加空白占位符
這篇文章主要介紹了vue的ElementUI form表單如何給label屬性字符串中添加空白占位符問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-10-10

