Dynamicznie tworzyć i resetować tabIndex elementów HTML.
Atrybut tabindex określa kolejność elementów HTML, takich jak zestaw "li", "a" e.t.c. Atrybut tabindex jest obsługiwany we wszystkich głównych przeglądarkach.
Dla tej instancji ustaw tabindex dla pozycji listy "li". Zwykle tabindex zaczyna się od "0", ale możemy je zresetować, aby rozpocząć od "1". Używam Jquery, aby to zrobić.
See It Working Here
<ul id="dfruits">
<li>Apple</li>
<li>Dragonfruit</li>
<li>Damson</li>
<li>Cloudberry</li>
<li>Blueberry</li>
<li>Cherry</li>
<li>Blackcurrant</li>
<li>Coconut</li>
<li>Avocado</li>
<li>Pinaple</li>
</ul>
$(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('<br/><em>My tabIndex is number: '+tabIndex+'<em>')
})
});
+1 dla swojego awatara – MooGoo
$ ('# LINK3 ') .attr (' tabIndex ', 6); // dla jQuery – marklark
Atrybut to 'tabindex', ale' el.tabindex' nie działa, jednak działa 'el.tabIndex'. Bardzo dziwne. –