第二章 jQuery选择器

#选择器css

##基本选择器spa

  1. (#id)code

    根据给定的id匹配一个元素,$("#test")orm

  2. (.class)对象

    根据给定的类名匹配元素集合,$(".test")索引

  3. element 根据元素名匹配,$("td")element

    匹配全部元素input

  4. selector1,selector2 匹配每个元素后合并,$("div,span,p.class")it

##层级选择器io

  1. $("body div")

    后代元素
  2. $("body > div")

    内子元素
  3. $("one + div")

    下一个同辈元素,可用next()方法代替
  4. $("#tow ~ div")

    后面的同辈元素,可用nextAll()方法代替

##过滤选择器

  1. :first 匹配第一个元素
  2. :last 最后一个元素
  3. :not(selector) 排除
  4. :even 索引为偶数
  5. :odd 索引为基数
  6. :eq(index) 索引等于index
  7. :gt(index) 索引大于index
  8. :lt(index) 索引小于index
  9. :focus 获取焦点的元素

##内容过滤器

  1. :contains(text) 选取内容含有文本内容的元素
  2. :has(selector) 含有选择器匹配的元素 $("div:has(p)")

##属性过滤选择器

  1. [attribute] 选取拥有此属性的元素 $("div[id]")
  2. [attribute=value] 属性值为value的元素, $("div[title=test]")
  3. [attribute^=value] 属性值以value开始 $("div[title^=test]")
  4. [attribute$=value]
  5. [attribute*=value]

##子元素过滤器

  1. nth-child(index/even/odd)

    $("div.one :nth-child(2)").css("")	 
    
     改变每一个class为one的<div>父元素下的第二个字元素的css
  2. :first-child

  3. :last-child

##表单对象属性过滤选择器

  1. :enabled 选择表单内的全部可用元素

    $("#form1 :enabled")
  2. :disabled 选取不可用元素

    $("#form2 :disabled")
  3. :checked 选择全部被选中的元素(单选框,复选框)

    $("input :checked")
  4. :selected 选取全部被选中的选项元素

    $("select option:selected");
相关文章
相关标签/搜索