2
使用JQuery我們如何找到當前的第n個子元素被點擊的元素是,並提醒該數字。JQuery找到第n個孩子並顯示
$('.bouncetabs a').click(function(){
alert($(this + ':nth-child'))
return false
});
很明顯,這是行不通的。我們該怎麼做呢?
使用JQuery我們如何找到當前的第n個子元素被點擊的元素是,並提醒該數字。JQuery找到第n個孩子並顯示
$('.bouncetabs a').click(function(){
alert($(this + ':nth-child'))
return false
});
很明顯,這是行不通的。我們該怎麼做呢?
我想你想的.index method:中
var selector = '.bouncetabs a';
$(selector).click(function(){
//just .index() may work too, depending on the html
alert($(this).index(selector));
return false;
});
謝謝呀! .... –
可能重複[jQuery的 - 獲得一個元素的索引與某一類](http://stackoverflow.com/questions/3204349/jquery-get -a-a-index-of-a-class-class) – JJJ