jQuery——jQuery基础方法first()/last()/not(CSS选择器)/even/odd/eq(index)/gt(index)/lt(index)
2013-11-25 12:01
246 查看
<!--
jQuery——jQuery基础方法first()/last()/not(CSS选择器)/even/odd/eq(index)/gt(index)/lt(index)
:first()获取到jQuery对象中的第一个匹配元素
:last()获取到jQuery对象中的最后一个匹配元素
:not(CSS选择器)根据获取到的jQuery对象去除掉所有匹配的“CSS选择器”,获取最后的结果集
:even匹配所有索引值为偶数的元素,从 0 开始计数
:odd匹配所有索引值为奇数的元素,从 0 开始计数
:eq(index)匹配一个给定索引值的元素
:gt(index)匹配所有大于给定索引值的元素
:lt(index)匹配所有小于给定索引值的元素
注:这里需要记住,这些参数拼接成CSS选择器的差异性,以及是否可以通过jQuery对象进行方法获取,详细请看下面例子:
-->
例子如下:
<div id="name" class="">
<span id="" class="" >nani</span>
</div>
<div id="" class="">
kobicc
</div>
</body>
<script language="javascript">
<!--
alert($("div:first").html());
alert($("div").first().html()); //以上这两种方式都是正确的
alert($("div:last").html());
alert($("div").last().html()); //以上这两种方式都是正确的
alert($("div:not('#name')").html());
alert($("div").not('#name').html()); //以上这两种方式都是正确的
alert($("div:even").html());
alert($("div:odd").html());
alert($("div:eq(0)").html());
alert($("div").eq(0).html());
alert($("div:eq(1)").html());
alert($("div").eq(1).html());
//-->
</script>
jQuery——jQuery基础方法first()/last()/not(CSS选择器)/even/odd/eq(index)/gt(index)/lt(index)
:first()获取到jQuery对象中的第一个匹配元素
:last()获取到jQuery对象中的最后一个匹配元素
:not(CSS选择器)根据获取到的jQuery对象去除掉所有匹配的“CSS选择器”,获取最后的结果集
:even匹配所有索引值为偶数的元素,从 0 开始计数
:odd匹配所有索引值为奇数的元素,从 0 开始计数
:eq(index)匹配一个给定索引值的元素
:gt(index)匹配所有大于给定索引值的元素
:lt(index)匹配所有小于给定索引值的元素
注:这里需要记住,这些参数拼接成CSS选择器的差异性,以及是否可以通过jQuery对象进行方法获取,详细请看下面例子:
-->
例子如下:
<div id="name" class="">
<span id="" class="" >nani</span>
</div>
<div id="" class="">
kobicc
</div>
</body>
<script language="javascript">
<!--
alert($("div:first").html());
alert($("div").first().html()); //以上这两种方式都是正确的
alert($("div:last").html());
alert($("div").last().html()); //以上这两种方式都是正确的
alert($("div:not('#name')").html());
alert($("div").not('#name').html()); //以上这两种方式都是正确的
alert($("div:even").html());
alert($("div:odd").html());
alert($("div:eq(0)").html());
alert($("div").eq(0).html());
alert($("div:eq(1)").html());
alert($("div").eq(1).html());
//-->
</script>
相关文章推荐
- jquery基本过滤选择器:first :last :not(.myclass) :even :odd :eq(1) :gt(5) :lt(1) :header :animated :focus
- Jquery 过滤器(first,last,not,even,odd)的使用
- Jquery 过滤器(first,last,not,even,odd)的使用
- jQuery 遍历 - 过滤---first--last---eq--not--filter方法(二十五)
- Jquery 过滤器(first,last,not,even,odd)应用
- jquery笔记:筛选 eq,first,last,filter,is,has, not, children,closest, nextUntil,parents,parentsUntil.....
- JavaSE8基础 LinkedList<String> getFirst getLast 获取首尾元素
- 浅谈jQuery中对象遍历.eq().first().last().slice()方法
- 知识点七:jQuery 遍历 - 过滤first(), last() 和 eq(),filter() 和 not()
- JavaSE8基础 LinkedList<String> removeFirst removeLast 移除首尾元素
- jQuery原型方法first,last,eq,slice源码分析
- jquery过滤器(first,last,not,even,odd简单应用)
- 浅谈jQuery中对象遍历.eq().first().last().slice()方法
- Sender address<*@*>domain does not exist 的解决方法
- jquery 中$.post获取MVC Controller中JsonResult返回包含LIst<Model>类型的子List<Model>的高级使用方法
- jquery 自动触发<a> 标签的click()方法
- python 7-5 如何让类支持比较操作lt/le/total_ordering可以简化此过程,实现lt eq 后,可以推测出<= >=方法
- SQL Server XML基础学习之<6>--XML modify() 方法对 XML 数据中插入、更新或删除
- c# 扩展方法奇思妙用基础篇五:Dictionary<TKey, TValue> 扩展
- supervisorctl报错"error: <class 'socket.gaierror'>, [Errno -2] Name or service not known"的解决方法