[英]how can i trigger only one tab key if the tab key is pressed numerous times in a certain time period
how can i trigger only one tab key if the tab key is pressed numerous times in a certain time period or if the tab key is pressed and held in.Basically i want the tab key to move slowly between input fields regardless of how tab is pressed because currently it is moving to fast. 如果在特定时间段内多次按下Tab键或按住Tab键,我该如何仅触发一个Tab键。基本上,我希望Tab键在输入字段之间缓慢移动,而与如何按Tab键无关因为目前它发展很快。
var tab_counter = 0;
var time_counter = 0;
if (e.keyCode === 9) {
tab_counter = Number(tab_counter) + Number(1);
var interval = setInterval(function() {
time_counter++;
console.log(time_counter);
if (time_counter == 20 && tab_counter > 20) {
clearInterval(interval);
}
}, 60);
}
Best way to do it is to keep track of when the tab was last triggered and to preventDefault
when it should not trigger. 最好的方法是跟踪选项卡上一次触发的时间,并在不应该触发时阻止
preventDefault
。 If you add the event listener to the document
then every time the user presses a key you have the option to block it. 如果将事件侦听器添加到
document
则每次用户按下某个键时,您都可以选择阻止它。
Check this jsfiddle i created to show you the solution: https://jsfiddle.net/zLsbb0kh/1/ 检查我创建的此jsfiddle以向您显示解决方案: https ://jsfiddle.net/zLsbb0kh/1/
Cheers! 干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.