在Jquery中,您如何找到被点击的元素的'eq'?

Ste*_*hen 31 jquery

当点击"uploadChoice"中的一个div时,如何确定单击哪一个?我可以以某种方式返回'eq'值吗?

 <div id=uploadChoice>
     <div>Text</div>
     <div>Image</div<
    <div>Text & Image</div>
</div>



$("#uploadChoice div").click(function(){
    //insert code here! :)   
});
Run Code Online (Sandbox Code Playgroud)

bri*_*nng 64

$('#uploadChoice div').click(function(event) {
  var index = $(this).index();
});
Run Code Online (Sandbox Code Playgroud)


red*_*are 5

不需要复制选择器的更简单的替代方案如下

$('#uploadChoice div').click(function(event) {
  var index = $(this).prevAll().length;
});
Run Code Online (Sandbox Code Playgroud)