jQuery选择器

来源:互联网 发布:通达信软件 苹果 编辑:程序博客网 时间:2024/06/14 00:07

根据获取页面元素的不同,可以将jQuery选择器分为:基本选择器、层次选择器、表单选择器、过滤选择器四大类。其中,过滤选择器又可分为:简单过滤选择器、内容过滤选择器、可见性过滤选择器、属性过滤选择器、子元素过滤选择器、表单对象属性过滤选择器6种。


基本选择器:id,class,元素名,多个选择符组成

层次选择器:主要的层次关系包括后代、父子、相邻、兄弟关系。(prev+next可以使用.next()代替;prev~siblings可以使用.nextAll()代替)

                         *siblings()方法与选择器prev~siblings区别在于,前者获取全部的相邻元素,不分前后,而后者仅获取标记后面全部相邻元素,不能获取前面部分。

表单选择器 :  :input,:text,:password,:radio,:checkbox,:submit,:image,:reset,:button,:file11种常用的表单对象。

简单过滤选择器::first,:last,:not(selector),:even,:odd,:eq(index),:gt(index),:lt(index),:header,:animated

内容过滤选择器::contains(text),:empty,:has(selector),:parent

可见性过滤选择器::hidden,:visible (:hidden选择器选择的不仅包括样式为display:none,还包括属性type="hidden"和样式为visibility: hidden的所有元素)。

属性过滤选择器:[attribute],[attribute=value],[attribut!=value],[attribute^=value],[attribute$=value],[attribute*=value],[selector1][selector2][selectorn]。

子元素过滤选择器::nth-child(eq|even|odd|index),:first-child,:last-child,:only-child。

表单对象属性选择器::enabled,:disabled,:checked,:selected。