Focus Next Element In Tab Index

后端 未结 20 2173
失恋的感觉
失恋的感觉 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条回答
  •  旧时难觅i
    2020-11-27 03:29

    Did you specify your own tabIndex values for each element you want to cycle through? if so, you can try this:

    var lasTabIndex = 10; //Set this to the highest tabIndex you have
    function OnFocusOut()
    {
        var currentElement = $get(currentElementId); // ID set by OnFocusIn 
    
        var curIndex = $(currentElement).attr('tabindex'); //get the tab index of the current element
        if(curIndex == lastTabIndex) { //if we are on the last tabindex, go back to the beginning
            curIndex = 0;
        }
        $('[tabindex=' + (curIndex + 1) + ']').focus(); //set focus on the element that has a tab index one greater than the current tab index
    }
    

    You are using jquery, right?

提交回复
热议问题