备注:我在工作中遇在一个文字出现是可以按键盘事件的但只允许按键一次并记录结果,这个时候再次字体消失,然后直到字体再出现的时候就在开启键盘事件
出现字体开启
this.showResultContTimer = setTimeout(() => {
this.keyUpResult();
this.isShowPlus = false;
this.isShowTestCont = true;
}, this.fixationShowTime);
keyUpResult() {
$(document).on('keyup', (e => {
if (e.keyCode === 37) {
this.testResultJson[this.testResultNumber].push(
{ rightKey: this.attributiveWordArray[this.questionNumber], answer: '1', time: 0}
)
console.log('左键');
clearTimeout(this.showTestContTimer);
clearTimeout(this.showResultNextTimer);
if (this.questionNumber < this.attributiveWordArray.length) {
this.isShowTestCont = false;
this.isShowPlus = true;
this.questionNumber++;
this.showresultCont();
}
$(document).off('keyup');
}
})
}