Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
705 views
in Technique[技术] by (71.8m points)

jquery - Capture "shift+tab" keypress event

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();
        }
    }
});

Now I want to move tah tab in backward direction as well. Can somebody guide me how can i achieve this???

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use e.shiftKey to check whether the shift key was held when the event was triggered.

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
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...