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 | E-pasts Get updates via feedburner Get updates via twitter
Home / Coding / JavaScript & Ajax / JavaScript: How to get the i… Home / kodēšanas / JavaScript un Ajax / JavaScript: Kā iegūt i ...

JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: Kā nokļūt indekss (amatu grupā) un objekts ar jQuery?

Posted on 20. Posted on 20. Jun, 2009 by Dragos in Coding , JavaScript & Ajax Jun, 2009 by Dragos in Kodēšana, JavaScript un Ajax

I've spent some time today figuring out how to obtain that index and finally I've just puzzled it out. Esmu pavadīju kādu laiku šodien norādītas, kā iegūt šo indeksu un beidzot es esmu vienkārši neizprot to ārā.

Let's say we have a group of objects all containing the class=”house”. Let's say mums ir grupa objektu visu satur class = "māja". 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: Tagad, ja mums ir norādes uz pirmo elements grupā, un mēs gribētu uzzināt, tas ir indekss (arī tas ir skaidrs, šajā gadījumā), mēs gribētu izmantot šo gabalu kodu:

 var indexOfFirstElement=$('.house').index($('.house:first')); //indexOfFirstElement=0; var indexOfFirstElement =$('. māja "). indekss ($('. māja, pirmais ')); / / indexOfFirstElement = 0; 

So, the code works as follows: we're searching within all elements of a group all grouped by the class=”house” ( $('.house') ). Tātad, kods darbojas šādi: mēs esam meklēšanu visiem grupas visu sagrupēti pēc class = "spēļu nams" ($ ( '. Māja ") elementi). 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')) ). Tagad mēs meklējam indekss, ja elements šajā grupā, mūsu gadījumā tas ir pirmais elements grupā ($ ( '. Māja "). Indekss ($('. māja: pirmais"))).

Here's another example to help you better understand how index() works: Lūk vēl viens piemērs, kas palīdzēs jums labāk izprast, kā indekss () darbi:

 $('.house').each(function(i){ $ ( '. māja "). katras (function (i) ( 
      if(i==3) alert($('.house').index(this)); //alerts 3, supposing there are 3 or more elements with class="house" if (i == 3) brīdinājums ($('. māja "). index (this)); / / Alerts 3, pieņemot, ka ir 3 vai vairāki elementi, ar class =" spēļu nams " 
 }); )); 

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. Vārdu sakot, ja jums nepieciešams noskaidrot indekss elements grupā, jums vispirms norādīt grupu un pēc tam nodot objektu jāatrod indeksu kā parametru indekss () funkciju.

Translate this post Tulkot šo ziņu


Related posts: Related posts:

  1. JavaScript: GIFless animation. JavaScript: GIFless animāciju. Animate images,logos with jQuery Dzīva attēlus, logotipus ar jQuery
  2. JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Sūtīt funkcija kā parametru citai funkcijai (callbacks)
  3. JavaScript: What if jQuery animation doesn't fire/start? JavaScript: Ko darīt, ja jQuery animācijas nav uguns / sākt?
  4. JavaScript: Where do I Find All Properties for All HTML Elements ? JavaScript: Kur es varu atrast visas Properties visiem HTML elementiem?
  5. Javascript: How to validate email address with JavaScript? Javascript: Kā lai apstiprinātu e-pasta adresi ar JavaScript?

    blog comments powered by Disqus blog komentāriem powered by Disqus