我设置了一个简单的 jquery 选项卡小部件。它一开始有两个选项卡,一个是错误 1,一个是加号。单击加号会添加错误 2 选项卡。再次单击它会添加错误 3 选项卡。问题是单击加号后无法从选项卡中删除选项卡索引。 RemoveAttr('tabIndex') 在页面加载时起作用,以防止第一个选项卡具有索引,但是在单击加号后,我还没有找到从其余选项卡中删除选项卡索引的方法。我将removeAttr() 放在.show() 之后。我把它放在那一行之前。我尝试将它放在 activate、load、beforeload 和 create 中。我尝试设置 tabindex=-1 而不是removeattr()。我还尝试过摆脱隐藏/显示并使用 css 来显示/不显示。
$(document).ready(function(){
$("#tabs").tabs({
beforeActivate: function (event, ui) {
if (ui.newTab.attr('id') == 'liTabsPlus') {
event.preventDefault();
errorTabsShowing += 1;
$('#liTabs' + errorTabsShowing).show();
$(this).tabs('option', 'active', errorTabsShowing - 1);
if (errorTabsShowing == MAX_NUMBER_OF_ERRORS)
ui.newTab.hide();
}
}
});
$("#liTabs1").removeAttr("tabIndex");
$("#liTabs2").hide();
$("#liTabs3").hide();
$("#liTabs4").hide();
}
最佳答案
如果没有看到您的标记,很难说,但我是通过循环遍历元素并将选项卡索引设置为 -1 来完成此操作的。这是一个对所有以“liTabs”id 开头的选项卡执行此操作的示例,例如 liTabs1、liTabs23 等。
$('[id^=liTabs]').each(function(){ this.tabIndex = -1; });
希望这有帮助
关于javascript - 无法从 jquery 选项卡小部件中删除 tabIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13352919/