Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
728 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...