2010-09-22 77 views

回答

42
document.getElementById("link3").tabIndex = 6; 
+4

+1爲你的頭像 – MooGoo 2010-09-22 18:56:16

+5

$('#LINK3 ').attr('tabIndex',6); //對於jQuery – marklark 2014-07-31 18:10:39

+0

屬性是'tabindex',但'el.tabindex'不起作用,但是'el.tabIndex'。太奇怪了。 – 2017-02-12 03:44:50

0

動態創建並重置HTML元素的tabIndex。

tabindex屬性指定HTML元素(例如「li」,「a」e.t.c的集合)的Tab鍵順序。所有主流瀏覽器都支持tabindex屬性。

對於這個實例,讓列表項「li」設置tabindex。通常tabindex將從'0'開始,但是我們可以將它重置爲從'1'開始。我正在使用Jquery來做到這一點。

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>') 
}) 
    }); 
4

使用JQuery我們可以設置標籤索引動態容易 試試這個代碼 - 設置tabindex並增加可變

$(function() { 
    var tabindex = 1; 
    $('input,select').each(function() { 
     if (this.type != "hidden") { 
      var $input = $(this); 
      $input.attr("tabindex", tabindex); 
      tabindex++; 
     } 
    }); 
}); 
+0

這是完美的,謝謝! – 2015-05-01 20:46:18

相關問題