我可以在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>')
})
    });
智能推荐

注意!

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



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

赞助商广告