<div>
<b>this is b</b>
</div>
<div>
<p>this is span</p>
<p>this is span</p>
<b>this is b</b>
<b>this is b</b>
</div>
    //  $(this).index() 测试代码一
$("b").on("click",function(){
var index = $(this).index();
console.log(index); // 依次点击b元素输出:2,3
})
// $(obj).index(this) 测试代码二
$("b").on("click",function(){
var index = $("b").index(this);
console.log(index); // 依次点击b元素输出:0,1,2
})

测试代码一中,$(this).index()获取当前标签在同级标签中的索引,不区分标签。

测试代码二中,$("b").index(this)获取所有同类标签中当前标签的索引。

随机推荐

  1. JavaScript 四种显示数据方式

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. SAP数据表相关

    [转]SAP 数据表相关信息 今天用到了根据字段取数据元素描述,以前做过忘啦,在谢兄的帮助下搞定,把他的总结粘出来记住. 存储域(Domain)信息的表为DD01L:存储数据元素(Data Eleme ...

  3. Android Development Note-02

    输入框左侧的logo:android:drawableleft   弹出提示: Toast.makeText(this,"提示",Toast.LENGHT_LONG).show() ...

  4. POJ - 2299 Ultra-QuickSort 【树状数组+离散化】

    题目链接 http://poj.org/problem?id=2299 题意 给出一个序列 求出 这个序列要排成有序序列 至少要经过多少次交换 思路 求逆序对的过程 但是因为数据范围比较大 到 999 ...

  5. A. Playing with Paper

    这是Codeforces Round #296 (Div. 2)的A题,题意就是: 小明有一张长为a,宽为b的纸,每当要折纸鹤时,就从纸上剪下一个正方形,然后,剩下的纸还可以剪出正方形,要是剩下的纸刚 ...

  6. luoguP3066 [USACO12DEC]逃跑的BarnRunning

    luoguP3066 [USACO12DEC]逃跑的BarnRunning 题目大意 给定一棵n个节点的树和参数L,查询每个节点子树中到达该节点距离<=L的数量(包括该节点) 偏模板的主席树 P ...

  7. vector缩减容量

    在C++标准库容器vector的容量是不会自动的缩减的,也就是说删除元素操作,其引用.指针.迭代器也会继续有效.那么当在一个较大的vector中删除了大量的元素之后,其实际的size比较小,而其cap ...

  8. CodeForces - 960F Pathwalks —— 主席树(n棵线段树)

    题目链接:https://vjudge.net/problem/CodeForces-960F You are given a directed graph with n nodes and m ed ...

  9. python基本模块相关信息

    系统相关的信息模块: import sys sys.argv 是一个 list,包含所有的命令行参数. sys.stdout sys.stdin sys.stderr 分别表示标准输入输出,错误输出的 ...

  10. listen and translation exercise 51

    You are supposed to be having fun now. I have to hand in my biology paper tomorrow. Listen, you litt ...