This is a translated page. The original can be found here: http://iwebdevel.com/2009/06/20/javascript-how-to-get-the-index-position-within-a-group-of-an-object-with-jquery/
UPDATES VIA RSS | Email 업데이 트를 통해 RSS | 이메일 Get updates via feedburner Get updates via twitter
Home / Coding / JavaScript & Ajax / JavaScript: How to get the i… / 코딩 / 자바 스크립트 & 아약스 / 자바 스크립트 : 어떻게 내가 가지려고한다면 ..

JavaScript: How to get the index (position within a group) of an object with jQuery? 자바 스크립트 : 어떻게 jQuery와 개체의 (위치를 그룹 내에서) 인덱스를 얻을가?

Posted on 20. 20 게시됨. Jun, 2009 by Dragos in Coding , JavaScript & Ajax 6 월, 2009 코딩, 자바 스크립트 & 아약스에서 드라 고스에 의해

I've spent some time today figuring out how to obtain that index and finally I've just puzzled it out. 오늘 내가하는 방법 및 그 색인을 구하는 방법 드디어 난 그냥 좀 당황 했어요 알아내는 시간을 할애했습니다.

Let's say we have a group of objects all containing the class=”house”. 우리가 물체의 모든 클래스를 포함하는 그룹이 있다고 가정해 봅시다 = "집". Now if we are referencing to the first element within the group and we'd like to find out it's index (well it's obvious in this case), we'd use this piece of code: 이제 우리는 첫 번째 요소를 참조하는 그룹 내에 우리는 그것의 색인 (물론이 경우에는 분명 알게하고 싶습니다), 우리는이 코드 조각을 사용하십시오 :

 var indexOfFirstElement=$('.house').index($('.house:first')); //indexOfFirstElement=0; var indexOfFirstElement =$('. 집 '). 색인 집을 ($('. : 먼저')); / / indexOfFirstElement = 0; 

So, the code works as follows: we're searching within all elements of a group all grouped by the class=”house” ( $('.house') ). 그래서 코드는 작동은 다음과 같습니다 : 우리 그룹의 모든 클래스에 의해 = "집"($ ( '. 집은') 그룹화의 모든 구성 요소 내에서 검색할 수있어). Now we are looking for the index if an element within this group, in our case it's the first element of the group ( $('.house') .index($('.house:first')) ). 이제 우리는 색인을 찾고있다면 우리의 경우이 그룹 내에서 그룹의 첫 번째 요소 ($ ( '. 집에'의 요소). 색인 집을 ($('. : 먼저 '))).

Here's another example to help you better understand how index() works: 여기 당신이 더 나은 방법을 지수 () 작품 이해를 돕기 위해 다른 예제 :

 $('.house').each(function(i){ $ ( '. 집은'). 각 (함수는 (i) ( 
      if(i==3) alert($('.house').index(this)); //alerts 3, supposing there are 3 or more elements with class="house" 경우는 (i == 3) 경고 ($('. 집 '). 색인 (이)); / / 거기에 수업을 3 개 이상의 요소 = "집이있습니다 랬"3 알림 
 }); )); 

So basically, if you need to find out the index of an element within a group, you should first specify the group and then pass the object you need to find the index of as a parameter to the index() function. 그러니까 기본적으로, 만약 당신이 그룹 내에서 요소의 색인을 찾을 필요가 먼저 그리고 당신의 색인을 찾을 필요가 개체를 전달 그룹을 지정해야합니다 색인에 매개 변수로 () 함수.

Translate this post 번역이 게시물에


Related posts: 관련 게시물 :

  1. JavaScript: GIFless animation. 자바 스크립트 : GIFless 애니메이션. Animate images,logos with jQuery 애니메이션 이미지를 jQuery와 로고
  2. JavaScript: Send function as a parameter to another function (callbacks) 자바 스크립트 : 다른 함수 (콜백)를 매개 변수로 함수를 보내기
  3. JavaScript: What if jQuery animation doesn't fire/start? 자바 스크립트 : 어떤 경우에는 jQuery 애니메이션 쏘지 / 시작합니까?
  4. JavaScript: Where do I Find All Properties for All HTML Elements ? 자바 스크립트 : 어디에서 모든 HTML 요소에 대한 모든 속성을 찾을 수 있습니까?
  5. Javascript: How to validate email address with JavaScript? 자바 스크립트 : 자바 스크립트와 방법의 이메일 주소를 확인하려면?

    blog comments powered by Disqus 블로그 덧글 Disqus에 의해 제공