开发者社区 问答 正文

点击的时候怎么获取上一个点击元素的下标

`$('li').on('click',function(){
console.log($(this).index())
})`不是点击当前元素的上一个,是比如我第一次点了第3个,第二次点了第7个,我怎么获取到第一次点的位置

展开
收起
小旋风柴进 2016-03-19 11:16:44 2113 分享 版权
1 条回答
写回答
取消 提交回答
  • 
        var preIndex = -1;
        $('li').on('click', function () {
            console.log(preIndex)
            preIndex = $(this).index()
            console.log($(this).index())
        })
    2019-07-17 19:07:46
    赞同 展开评论
问答地址: