Javascript 获取已单击元素的节索引

Javascript 获取已单击元素的节索引,javascript,html,jquery,Javascript,Html,Jquery,在我的网站上,我需要得到一个点击元素部分的索引 有一个和多个,每个都有一个。 每个节都有自己独特的节标题 如果单击一个列表元素,类将从listfuitem有拍卖数据变为listfuitem有拍卖数据处于活动状态(尝试在操场上重建) 在上,一次只能激活一个列表元素。(不是在这个网站上工作,而是在网站上) 目前,我的代码是这样工作的: itemList=document.querySelectorAll('.sectioneditemlist>ul')[2] 但指数必须是可变的 $('.listf

在我的网站上,我需要得到一个点击元素部分的索引

有一个
和多个
,每个
都有一个
。 每个节都有自己独特的节标题

如果单击一个列表元素,类将从
listfuitem有拍卖数据
变为
listfuitem有拍卖数据处于活动状态
(尝试在操场上重建)

上,一次只能激活一个列表元素。(不是在这个网站上工作,而是在网站上)

目前,我的代码是这样工作的:
itemList=document.querySelectorAll('.sectioneditemlist>ul')[2]
但指数必须是可变的

$('.listfuittem')。单击(函数(){
$(this.sibles().filter('.active').removeClass('active');
$(this.addClass('ListFutiItem的拍卖数据处于活动状态');
log($('.listFUTItem.has auction data').index(this));
});
.active{
背景:#00FF00;
}
.ut节标题视图{
填充物:75雷姆。5雷姆;
背景色:#F2F2;
框大小:边框框;
显示器:flex;
字体系列:无衬线;
溢出:隐藏;
文本转换:大写;
}
Listfuittem先生{
显示器:flex;
}

售出物品
    巴拉克有拍卖数据
  • Lehmann
  • Pique
  • 克朗
  • Owen
未售出物品
    巴拉克有拍卖数据
  • Lehmann
  • Pique
  • 克朗
  • Owen
使用
最近的()
遍历到
并在该类的所有部分集合中获取其索引

const$sections=$('.sectioned item list');
$('.listfuitem')。单击(函数(){
const$sect=$(this).closest('.sectioned item list');
const sectIndex=$sections.index($sect);
console.log(sectIndex)
});
.active{
背景:#00FF00;
}
.ut节标题视图{
填充物:75雷姆。5雷姆;
背景色:#F2F2;
框大小:边框框;
显示器:flex;
字体系列:无衬线;
溢出:隐藏;
文本转换:大写;
}
Listfuittem先生{
显示器:flex;
}

未售出物品
    巴拉克有拍卖数据
  • Lehmann
  • Pique
  • 克朗
  • Owen
售出物品
    巴拉克有拍卖数据
  • Lehmann
  • Pique
  • 克朗
  • Owen
可用项目
    巴拉克有拍卖数据
  • Lehmann
  • Pique
  • 克朗
  • Owen
未售出物品
    巴拉克有拍卖数据
  • Lehmann
  • Pique
  • 克朗
  • Owen

您可以使用
jQuery
进行此操作。使用
$('.transferlist section ul li.active').removeClass('active')
从所有活动列表项中删除
.active
类。运行以下代码段以检查结果:

$(this).index();
反对

$(".listFUTItem.has-auction-data").index(this);
$('.listfuittem')。单击(函数(){
$('.transferlist节ul li.active').removeClass('active');
$(this.addClass('ListFutiItem的拍卖数据处于活动状态');
console.clear();
log('$(this).index()值为->\t'+$(this.index());
console.log('$(this.parents(“section”).index()值为->\t'+$(this.parents(“section”).index());
console.log('$(“.listfuitem.has auction data”)。索引(此)值为->\t'+$('.listfuitem.has auction data')。索引(此));
});
.active{
背景:#00FF00;
}
.ut节标题视图{
填充物:75雷姆。5雷姆;
背景色:#F2F2;
框大小:边框框;
显示器:flex;
字体系列:无衬线;
溢出:隐藏;
文本转换:大写;
}
Listfuittem先生{
显示器:flex;
}

未售出物品
    巴拉克有拍卖数据
  • Lehmann
  • Pique
  • 克朗
  • Owen
售出物品
    巴拉克有拍卖数据
  • Lehmann
  • Pique
  • 克朗
  • Owen
可用项目
    巴拉克有拍卖数据
  • Lehmann
  • Pique
  • 克朗