2011-03-22 3 views
1

아무도 클릭 한 클래스의 배열 인덱스를 어떻게 감지 할 수 있는지 알려 줄 수 있습니까?MooTools - 클래스의 배열 인덱스를 찾았습니다.

내가 가진 그래서 경우 :

HTML

<span class="test">first</span> 
<span class="test">second</span> 
<span class="test">third</span> 

Mootools의 JS

$$('.test').addEvent('click', function(event){ 
       // alert(this array index); 
}); 

를 어떤 도움이 좋을 것, 감사합니다!

답변

2

매우 간단합니다 - 당신을위한 .each을하지만, 쓸 것입니다하지 .addEvent.each 자신을 대신 element, index 지원

$$('.test').each(function(el, index) { 
    el.addEvent('click', function(event){ 
     alert(index); // 0, 1, 2 
    }); 
});