我的html代码是

<input type="button" class="buttonclose marleft fleft clrPric" value="X">
<input type="button" class="buttonclose marleft fleft clrPric" value="X">
<input type="button" class="buttonclose marleft fleft clrPric" value="X">
<input type="button" class="buttonclose marleft fleft clrPric" value="X">


我给了jquery像

 $('.clrPric').click(function(){
    console.log($(this).index());
 });


它在控制台中仅显示7。此类中没有其他元素。
我想获取单击按钮的编号。

提前致谢。

最佳答案

您需要这样做:

$('.clrPric').click(function () {
    console.log($(this).index('.clrPric'));
});


FIDDLE

09-25 15:29