我需要创建一个仅在按特定顺序按下四个键后才触发的事件。我不是jquery的专家,可以这样做吗?
我已经知道如果按4会触发警报,但是我不知道在按特定顺序按四个键后如何触发警报。
$(document).keydown(function(keyPressed) {
if (keyPressed.keyCode == 52) {
alert("Hello!");
}
});
答案 0 :(得分:0)
您可以这样使用:
d = {'1':['Q4 2018', 100, 111, 222],
'2':[2018, 333, 444, 555],
'3':['Q1 2019', 55, 789, 70]}
df = pd.DataFrame(d)
答案 1 :(得分:0)
使用优质的老式普通Javascript,以下是镜头:
const code = "4352", sequence = [...code];
let keysPressed = [];
document.addEventListener('keydown', (event) => {
keysPressed.push(event.key);
if (keysPressed.every((key, index) => key === sequence[index])) {
if (keysPressed.length === sequence.length) {
alert('correct code entered!');
} else { return; }
}
keysPressed = [];
})
仅使用String
而不是Array
的替代解决方案:
const code = "4352";
let keysPressed = "";
document.addEventListener('keydown', (event) => {
keysPressed += event.key;
if (code.substr(0, keysPressed.length)===keysPressed) {
if (keysPressed === code) {
alert('correct code entered!');
} else { return; }
}
keysPressed = "";
})