我正在尝试创建一个chrome扩展来了解订单输入错误,当用户拼写错误11而不是1发送警报时,但脚本在循环中运行
document.querySelector('body').addEventListener('keydown', function() {
var tecla = event.keyCode;
if (tecla == 49) {
alert('Primeiro IF');
document.querySelector('body').addEventListener('keydown', function(event) {
var confirma = event.keyCode;
if (confirma == 49) {
alert('segundo IF');
return false;
}
});
} else if (tecla == 9) {
alert('Tecla 9');
return false;
}
});
发布于 2020-08-10 20:42:41
每次键入以下命令时,都会添加一个新的事件侦听器
试试这个:
let tecla, confirma;
document.querySelector('body').addEventListener('keydown', function() {
tecla = event.keyCode;
if (tecla == 49) {
if (confirma == 49) {
console.log('Segundo 1');
return false;
} else {
console.log('Primeiro 1');
confirma = tecla
}
} else if (tecla == 9) {
console.log('Tecla 9');
tecla = "";
confirma = "";
return false;
}
});
https://stackoverflow.com/questions/63340356
复制相似问题