Focus Next Element In Tab Index

后端 未结 20 2181
失恋的感觉
失恋的感觉 2020-11-27 03:06

I am trying to move the focus to the next element in the tab sequence based upon the current element which has focus. Thus far I have not turned up anything in my searches.<

20条回答
  •  孤街浪徒
    2020-11-27 03:31

    This is a potential enhancement to the great solution that @Kano and @Mx offered. If you want to preserve TabIndex ordering, add this sort in the middle:

    // Sort by explicit Tab Index, if any
    var sort_by_TabIndex = function (elementA, elementB) {
        let a = elementA.tabIndex || 1;
        let b = elementB.tabIndex || 1;
        if (a < b) { return -1; }
        if (a > b) { return 1; }
        return 0;
    }
    focussable.sort(sort_by_TabIndex);
    

提交回复
热议问题