Simulate pressing tab key with jQuery

后端 未结 4 1091
不思量自难忘°
不思量自难忘° 2020-12-09 15:14

I have some textboxes on a .net-page and want to achieve the following with jQuery: if the user presses return, the program should behave \"as if\" he had used the tab key,

4条回答
  •  有刺的猬
    2020-12-09 15:50

    I created a simple jQuery plugin which does solve this problem. It uses the ':tabbable' selector of jQuery UI to find the next 'tabbable' element and selects it.

    Example usage:

    // Simulate tab key when enter is pressed           
    $('.tb').bind('keypress', function(event){
        if(event.which === 13){
            if(event.shiftKey){
                $.tabPrev();
            }
            else{
                $.tabNext();
            }
            return false;
        }
    });
    

提交回复
热议问题