window.addEventListener("keydown", this.KeyDown);
监听键盘事件
KeyDown(event) {
const e = event || window.event || arguments.callee.caller.arguments[0];
let key = e.keyCode; //键盘码值 keycode
if (key == 13) {
this.qfFlag = false
return
}
if (key == 37) { //左
this.textIndex = 0
this.currentCol--;
if (this.currentCol < 0) {
this.currentCol = 0
}
} else if (key == 38) { //上
this.textIndex = 0
this.currentLine--;
if (this.currentLine < 0) {
this.currentLine = 0
} else {
this.currentCol = this.currentCol - 6
}
} else if (key == 39) { //右
this.textIndex = 0
this.currentCol++;
if (this.currentCol > this.htmlLength-1) {
this.currentCol = this.htmlLength-1
}
} else if (key == 40) { //下
this.textIndex = 0
this.currentLine++;
if (this.currentLine > this.currentLineMax - 1) {
this.currentLine = this.currentLineMax -1
} else {
this.currentCol = this.currentCol + 6
}
}
// console.log(this.currentLine, this.currentCol)
if (this.htmlList[this.currentCol]) {
this.htmlList[this.currentCol].focus()
}
if (key !== 37 && key !== 39 && key !== 38 && key !== 40) {
this.textIndex++
if (this.textIndex === 1) {
console.log(this.currentCol, this.htmlList[this.currentCol])
this.htmlList[this.currentCol].value = ''
}
}
},
判断输入框数量
this.$nextTick(() => {
console.log(document.querySelectorAll('.editInput>input'))
this.htmlList = document.querySelectorAll('.editInput > input')
this.htmlLength = document.querySelectorAll('.editInput > input').length
this.currentLineMax = Math.ceil(this.htmlLength/6)
})
获取表格输入框