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 UPDATES VIA RSS | Email Get updates via feedburner Get updates via twitter
Home / Coding / JavaScript & Ajax / JavaScript: How to get the i… Home / Coding / JavaScript & Ajax / JavaScript: Paano upang makakuha ng ako ...

JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: Paano upang makuha ang index (na posisyon sa loob ng isang grupo) ng isang bagay na may jQuery?

Posted on 20. Posted on 20. Jun, 2009 by Dragos in Coding , JavaScript & Ajax Hunyo, 2009 sa pamamagitan ng Dragos sa Coding, JavaScript & Ajax

I've spent some time today figuring out how to obtain that index and finally I've just puzzled it out. Ko na ang oras na ginugol ng ilang araw na figuring out kung paano makakuha na index at sa wakas lamang ako ng tuliro ito.

Let's say we have a group of objects all containing the class=”house”. Ipagpalagay natin na kami ay may isang grupo ng mga bagay na naglalaman ng lahat ng klase = "bahay". 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: Ngayon, kung tayo ay sanggunian sa unang elemento sa loob ng mga grupo at nais naming malaman ito sa index (mabuti ito halata sa kasong ito), gusto namin na gamitin ito na piraso ng code:

 var indexOfFirstElement=$('.house').index($('.house:first')); //indexOfFirstElement=0; var indexOfFirstElement =$('. bahay '). index ($('. bahay: unang')); / / indexOfFirstElement = 0; 

So, the code works as follows: we're searching within all elements of a group all grouped by the class=”house” ( $('.house') ). Kaya, ang code ay gumagana tulad ng sumusunod: namin na naghahanap sa loob lahat ng mga sangkap ng isang grupo sa lahat ng grupo sa pamamagitan ng class = "bahay" ($ ( '. 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')) ). Ngayon kami ay naghahanap ng mga index kung ang isang sangkap sa loob ng grupong ito, sa aming kaso ito ang unang elemento ng grupo ($ ( '. Bahay na'). Index ($('. bahay: unang '))).

Here's another example to help you better understand how index() works: Narito ang isa pang halimbawa para matulungan kayo na mas mahusay na maunawaan kung paano ang index () ang gumagana:

 $('.house').each(function(i){ $ ( '. bahay na'). bawat (function (i) ( 
      if(i==3) alert($('.house').index(this)); //alerts 3, supposing there are 3 or more elements with class="house" kung (i == 3) alerto ($('. bahay '). index (ito)); / / alerto 3, kaya may mga 3 o higit pang mga elemento na may class = "bahay" 
 }); )); 

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. Kaya karaniwang, kung kailangan mo upang alamin ang index ng isang sangkap sa loob ng isang grupo, dapat mo munang tukuyin ang grupo at pagkatapos ipasa ang mga bagay na kailangan mo upang mahanap ang indeks ng bilang ng isang parameter sa index () function.

Translate this post Isalin ang post na ito


Related posts: Related posts:

  1. JavaScript: GIFless animation. JavaScript: GIFless animation. Animate images,logos with jQuery Magpasaya mga imahe, mga logo na may jQuery
  2. JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Ipadala ang function bilang isang parameter sa isa pang function (callbacks)
  3. JavaScript: What if jQuery animation doesn't fire/start? JavaScript: Paano kung jQuery animation ay hindi sunog / simulan?
  4. JavaScript: Where do I Find All Properties for All HTML Elements ? JavaScript: Saan ko Maghanap Lahat ng mga Katangian para sa Lahat ng Mga Sangkap ng HTML?
  5. Javascript: How to validate email address with JavaScript? Javascript: Paano upang mapatunayan ang email address sa JavaScript?

    blog comments powered by Disqus blog comments powered by Disqus