2011-11-14 44 views
2

如何在jQuery中獲取Mootools中元素的索引。 例如:如何獲取Mootools中單擊元素的索引

this.controls.addEvent('click', function(event){ 
     if (this.hasClass('h-inactiveslideshowcontrol')) { 
      alert(this.index); 
     } 
    }); 

如何獲取點擊元素的索引?

回答

5

首先循環通過元素集合。

this.controls.each(function(element, index){ 
    element.addEvent('click', function(event){ 
     if (this.hasClass('h-inactiveslideshowcontrol')) { 
      alert(index); 
     } 
    }); 
}); 
+1

,他也可以做​​'this.controls.indexOf(本);' - 特別是如果委派使用 –

+0

哈,不錯,居然沒知道這一個。 –

+0

呃。 '的indexOf(元件)'。 do'h –

相關問題