目录
jQuery学习笔记
丰富的选择器
完整的列表在 http://api.jquery.com/category/selectors/ 。
常规选择器
$(“*”)
选择所有结点
(“#id”)
ID选择器,注意其中的一些特殊字符,比如 .
(“.class”)
类选择器
(“tag”)
按标签选择
(“ancestor descendant”)
选择子元素
(“parent > child”)
选择直接子元素
:focus
获取焦点元素
:first-child :last-child
选择第一个/最后一个子元素
:first :last
截取第一个/最后一个符合条件的元素
(“prev + next”)
直接兄弟元素
(“prev ~ siblings”)
兄弟元素
:nth-child()
索引选择,索引从 1 开始 :nth-child(odd) :nth-child(even) :nth-child(4n)
属性选择器
[name~=”value”]
属性中包括某单词
[name=”value”]
属性完全等于指定值
[name!=”value”]
属性不等于指定值
[name]
包括有指定属性的元素
控件选择器
:checked
选择所有被中的元素
:selected
被选择了的元素
:disabled :enabled
选择被禁用/未禁用的元素
:hidden
选择隐藏元素,不仅是 [type=”hidden”] ,还有 display: none
:visible
可见控件, visibility: hidden 和 opacity: 0 同样被认为是可见。
:input :button :checkbox :file :image :password :radio :reset :submit :text
具体控件,图像控件是 [type=”image”]
其它选择器
[name=”value”][name2=”value2″]
多个 AND 条件
(“selector1, selector2, selectorN”)
多个 OR 条件
:not()
否定选择
(‘:contains(“text”)’)
包含有指定内容的元素
:eq() :lt() :gt() :even :odd
列表索引选择(不支持负数)
(‘:has(selector)’)
符合条件的再次过滤
:header
选择像 h1,h2,h3 这些标题元素
:only-child
仅有一个子元素的元素
:empty
空元素,即无内容也无子元素
:parent
非空元素