捕获"shift + tab"按键事件 [英] Capture "shift+tab" keypress event
问题描述
我有一种情况,我想使用jquery捕获"shift + tab"键的同时按键事件.实际上,众所周知,它是用于向后移动制表符,但对我而言,在一种情况下,制表符无法在任何方向上起作用,即既不向前也不向后移动.所以我找到了一个jquery函数,用于向前移动标签,如下所示:-
I have a case where I want to capture the simultaneous key press event of "shift+tab" key using jquery. Actually as you all know it is used to move tab in backward direction but for me in one scenario tha tab was not working in any direction i.e. neither forward nor backward. so I found a jquery function for moving tab in forward direction as follows:-
$(':input').live('keydown', function(e) {
var keyCode = e.keyCode || e.which;
if (keyCode == 9) {
tindex = parseInt($(this).attr("tabindex")) + 1;
if($(":input[tabindex='" + tindex + "']"))
{
$(":input[tabindex='" + tindex + "']").focus();
}
}
});
现在,我也想将tah标签也向后移动. 有人可以指导我如何实现这一目标吗?
Now I want to move tah tab in backward direction as well. Can somebody guide me how can i achieve this???
推荐答案
您可以使用e.shiftKey
检查事件触发时是否按住了Shift键.
You can use e.shiftKey
to check whether the shift key was held when the event was triggered.
如果在事件处理程序中添加if
语句,检查是否按住Shift键,则可以执行不同的操作:
If you add an if
statement to your event handler, checking whether the shift key was held, you can perform different actions:
if(keyCode == 9) {
if(e.shiftKey) {
//Focus previous input
}
else {
//Focus next input
}
}
这篇关于捕获"shift + tab"按键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!