$(this).index()与$(obj).index(this)的区别
<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)获取所有同类标签中当前标签的索引。
随机推荐
- Linux就该这么学--Shell脚本基本应用
1.接收用户的参数: Shell脚本为了能够让用户更灵活的完成工作需求,可以在执行命令时传递参数:(命令名 参数1 参数2...) Shell预定义变量: $0 当前执行Shell脚本的程序名 $1- ...
- Java for LeetCode 132 Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- ruby 字符串
字符串处理函数 1.返回字符串的长度 str.length => integer 2.判断字符串中是否包含另一个串 str.include? other_str => true or fa ...
- 7-3 堆栈模拟队列(25 point(s)) 【数据结构】
7-3 堆栈模拟队列(25 point(s)) 设已知有两个堆栈S1和S2,请用这两个堆栈模拟出一个队列Q. 所谓用堆栈模拟队列,实际上就是通过调用堆栈的下列操作函数: int IsFull(Stac ...
- js正則函數 match、exec、test、search、replace、split 使用介紹集合
match 方法 使用正則表達式模式對字元串執行查找,並將包含查找的結果作為數組返回. stringObj.match(rgExp) 參數 stringObj 必選項.對其進行查找的 String 對 ...
- poj2965 The Pilots Brothers' refrigerator —— 技巧性
题目链接:http://poj.org/problem?id=2965 题解:自己想到的方法是枚举搜索,结果用bfs和dfs写都超时了.网上拿别人的代码试一下只是刚好不超时的,如果自己的代码在某些方面 ...
- vsftpd虚拟用户【公司系统部分享】
一,安装相关工具包 #yum -y install pam vsftpd db4 db4-utils -- pam 是用来提供身份验证的 -- vsftpd 是ftp服务的主程序 -- db4支持文件 ...
- blog集合
godiscoder的技术blog 一个不错的技术架构设计blog MySQLOPS 数据库与运维自动化技术分享 stone的技术blog 陈皓专栏 风雪涟漪的技术blog 华为首席科学家 张宴技术b ...
- Java中内部类中使用外面变量为什么final修饰?
所以final从语法上约束了实际上两个不同变量的一致性(表现为同一变量). 我的理解: 例如这样的代码: public void test(String str){ str="abc&quo ...
- leetcode 43. Multiply Strings(高精度乘法)
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...