迭代Jquery中启用的选项卡

Iterate over enabled tabs in Jquery

本文关键字:选项 启用 Jquery 迭代      更新时间:2023-09-26

我可以使用以下代码遍历所有制表符

$('#tabs .ui-tabs-nav a').each(function() {
      var id = $(this).attr('href');
}

(由https://forum.jquery.com/topic/how-to-iterate-through-tabs提供)

我可以检查一个选项卡是否被启用,通过它的索引使用以下代码

function isDisabled(index) {
  return $.inArray(index, $("#tabs").tabs("option", "disabled")) > -1;
}

(由Nick Craver从如何知道一个选项卡是否在jQuery选项卡上启用?)

如何遍历所有启用的选项卡?

您可以使用$.filter删除那些被禁用的,然后在剩余的$.each上:

$('#tabs .ui-tabs-nav a').filter(function(index) {
    return !isDisabled(index);
}).each(function() {
  var id = $(this).attr('href');
});

或者你可以$.not:

$('#tabs .ui-tabs-nav a').not(isDisabled).each(function() {
  var id = $(this).attr('href');
});