keydown事件上的Element.focus()正在通过可聚焦元素传递到下一个元素,而没有停止在第一个可聚焦元素上

时间:2019-03-28 01:27:10

标签: javascript jquery

在页面上的最后一个元素上点击后,

设置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
        }
      } );

如果上面的代码正常工作,我应该放弃以下所示的操作: enter image description here

0 个答案:

没有答案