我可以在JavaScript中動態設置tabindex嗎?

[英]Can I dynamically set tabindex in JavaScript?


Is there any attribute like tab-index?

是否有像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-index manually when that particular section is visible.

背景:我正在使網頁表單中的某個部分可見或不可見,具體取決於我希望在特定部分可見時手動設置制表符索引的某些條件。

3 个解决方案

#1


48  

document.getElementById("link3").tabIndex = 6;

#2


4  

Using JQuery we can set tab index dynamically easily Try this code- set the tabindex and increment the variable

使用JQuery我們可以輕松地動態設置選項卡索引嘗試此代碼 - 設置tabindex並增加變量

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

#3


0  

Dynamically create and reset tabIndex of an HTML elements.

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

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.

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

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.

對於此實例,請為列表項“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>')
})
    });
关注微信公众号

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2010/09/22/7def64f8e8246fdd248dcd18c1b7173f.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com