$(this).index(".change");
或者
$(".change").index(this);

解决方案 »

  1.   

    添加点击事件需要便利button添加
      

  2.   

    注意你得选择器,$(this)是获取本身,你点击的是一个按钮,获得本身就只是获得了你点击的按钮,是无法获得所有按钮的。<!doctype html>
    <html>
    <head>
    <title>test</title>
    <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script>
    <script type="text/javascript">
    $(function(){
    $(".btn_a").click(function(){
    var btn_n=$(".btn_a").index(this);
    console.log(btn_n);
    alert(btn_n);
    })
    })
    </script>
    </head>
    <body>
    <div>
    <button class="btn_a">1</button>
    </div>
    <div>
    <button class="btn_a">2</button>
    </div>
    </body>
    </html>
      

  3.   

    <ul>
      <li id="foo">foo</li>
      <li id="bar">bar</li>
      <li id="baz">baz</li>
    </ul>$('#bar').index(); //1,不传递参数,返回这个元素在同辈中的索引位置。  !!!!!!!$('li').index(document.getElementById('bar')); //1,传递一个DOM对象,返回这个对象在原先集合中的索引位置
    $('li').index($('#bar')); //1,传递一个jQuery对象
    $('li').index($('li:gt(0)')); //1,传递一组jQuery对象,返回这个对象中第一个元素在原先集合中的索引位置
    $('#bar').index('li'); //1,传递一个选择器,返回#bar在所有li中的做引位置
      

  4.   

    $(this).parent().index()Web开发学习资料推荐
    ajax对象属性withCredentials
    Web前端开发