设置focus()并不会转到所需的元素,而是转到下一个元素
What i am trying to do is given a html if user goes to last focussable element of the page on tabbing that last element should take the user to all my contextual actions such as discard, edit, delete etc etc.
I have already tried the keydown event but it is not going to the exact element but the next element. Below is what I have done.
var focussableElement = $('.main-scrollable :focusable');
var lastFocussableElement = focussableElement[focussableElement.length - 1];
var id = lastFocussableElement.id
$('#'+id).on( 'keydown', function( e ) {
if( e.which == 9 ) {
$('#DiscardChangesContext').focus(); //This is the first element on my contextual actions
}
} );