Can I dynamically set tabindex in JavaScript?

后端 未结 4 1346
再見小時候
再見小時候 2020-12-01 06:02

Is there any attribute like tab-index?

CONTEXT : I\'m making a section in a web form visible or invisible depending on some condition where I want to set the tab-ind

4条回答
  •  一向
    一向 (楼主)
    2020-12-01 06:45

    Dynamically create and reset tabIndex of an HTML elements.

    The tabindex attribute specifies the tab order of an HTML element, such as set of "li","a" e.t.c. The tabindex attribute is supported in all major browsers.

    For this instance let set tabindex for list items "li". Usually tabindex will start from '0', however we can reset it to start from '1'. I am using Jquery to do this.

    See It Working Here

    • Apple
    • Dragonfruit
    • Damson
    • Cloudberry
    • Blueberry
    • Cherry
    • Blackcurrant
    • Coconut
    • Avocado
    • Pinaple
    $(document).ready(function() { var SomeFruitsList=$("ul#dfruits li"), //set tab index to starts from 1 tabindex = 0; SomeFruitsList.each(function() { // add tab index number to each list items tabindex++; $(this).attr("tabindex","TabIndex " +tabindex); var tabIndex = $(this).attr("tabindex"); // add tab index number to each list items as their title $(this).attr("title",tabIndex); $(this).append('
    My tabIndex is number: '+tabIndex+'') }) });

提交回复
热议问题