返回容器中特定于JQuery的单击

Return JQuery specific click in a container

本文关键字:JQuery 单击 返回      更新时间:2023-09-26

我想知道如何返回在索引中单击的特定子项的值。

通常默认行为是使用

var selected = $(this).index();

尽管这可以正常工作,但它不会从INSIDE返回索引,函数如下。

var selected;
$(container.children()).on('click', function() {
    selected = $(this).index();
    selected.siblings().fadeOut();
    selected.animate({
        width: 920,
        height: 440
    });
    selected.fadeOut();
});
//console.log(selected) = 'undefined'!

为什么会这样,什么是合适的解决方案?!

编辑:

请注意,我对这个问题进行了编辑,使其不那么具体和本地化,以便获得更好的投票。

Rick

简单地说:

console.log($(this).index());
  • http://api.jquery.com/index/