鍍金池/ 問答/HTML/ 每個block都綁定了onclick事情,點擊的時候怎么獲得當前點擊元素在父元素

每個block都綁定了onclick事情,點擊的時候怎么獲得當前點擊元素在父元素的索引值呢?

如題! 每個imgblock都綁定了onclick事情,我想獲得點擊元素的index,怎么獲得呢?
圖片描述

js部分大致是這樣?

   //點擊瀏覽大圖
    function showBigImg(buttons){

        var idnex =  $(buttons).index();
        console.log(index);
        
        }

但是無論單擊哪一個,都是0

回答
編輯回答
毀與悔
$.each($('.imgBlock'),function(index,el){
    $(this).click(function(){
    console.log(index);
    })
})
   function  showBigImg(buttons){
        buttons.parent().children().each(function(i,e){
            if($(this).is(buttons)){
                console.log(i)                
            }
        })
    }
2018年8月11日 11:26