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 يونيو ، 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; 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){ $ ( '. المنزل'). لكل منها (وظيفة) (ط) ( if(i==3) alert($('.house').index(this)); //alerts 3, supposing there are 3 or more elements with class="house" إذا كان (ط == 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. ذلك أساسا ، إذا كنت بحاجة لمعرفة الرقم القياسي للعنصر ضمن مجموعة ، يجب عليك أولا تحديد المجموعة ومن ثم تمرير الكائن تحتاج إلى إيجاد مؤشر كمعلمة للمؤشر () وظيفة.
Related posts: الوظائف ذات الصلة :
- JavaScript: GIFless animation. جافا سكريبت : GIFless للرسوم المتحركة. Animate images,logos with jQuery تحريك الصور والشعارات مع jQuery
- JavaScript: What if jQuery animation doesn't fire/start? جافا سكريبت : ماذا لو الرسوم المتحركة jQuery لا النار / تبدأ؟
- JavaScript: Send function as a parameter to another function (callbacks) جافا سكريبت : إرسال الدالة كمعلمة إلى وظيفة أخرى (رد)
- JavaScript: Where do I Find All Properties for All HTML Elements ? جافا سكريبت : أين يمكنني إيجاد جميع خصائص لجميع عناصر أتش تي أم أل؟
- JavaScript: Get anchor from URL جافا سكريبت : احصل على مرساة من رابط












































