zoukankan      html  css  js  c++  java
  • 选择器

    //jQuery选择器参考了CSS,基本上完全一致
    /*
    如果选择器无法获取页面中的元素,也不会报错 JavaScript使用document.getElementById或name去获取元素的时候,如果没有获取到,是会报错的
    $()获取到的永远是对象,所以,不能用这个函数去判断页面中是否存在某个元素.要 $().length == 0,表示页面中没有某个元素 或者转化成DOM对象进行判断 $()[0]


    基本选择器:id class 标签名
    #id 获取id为id的单个元素
    .class 获取class为class的所有元素
    element 获取标签名为element的所有元素
    selector1,selector2,...多个选择器的选择结果,取合集
    * 所有元素

    层次选择器:通过DOM元素之间的关系来获取特定的数据
    $("div span") div里的所有span元素
    $("div > span") div下,元素名为span的子元素(只相差一个层级)
    $(".one+div") class为one元素的下一个div元素 等价于 $(".one").next("div")
    $("#two~div") id为two元素后面的所有div的兄弟元素(同一层级) 等价于 $("#two").nextAll("div")
    $("#two").siblings("div") id为two元素同层级中所有的div元素

    过滤器选择器:
    基本过滤器
    :first 例:$("div:first") 说明:第一个div元素
    :last
    :not(selector)
    :even 偶数索引,index从0开始计数
    :odd: 奇数索引
    :eq(index) 第index个索引的元素
    :gt(index) 索引大于index
    :lt(index) 索引小于index
    :header 所有标题元素 h1~h6
    :animated 正在执行动画的元素

    内容过滤器
    :contains(text) 包含文本text
    :empty 不包含子元素或文本的空元素
    :has(selector) 例子 $("div:has(p)") 含有p元素的div元素
    :parent 含有子元素或文本的元素

    可见性过滤器
    :hidden 不可见元素,包括input中type=hidden与disabled:none visibility:hidden
    :visible 可见元素

    属性过滤器
    [attr] 例子$("div[id]") 拥有id属性的div元素
    [attr=value] 属性为value的元素 例子$("input[type='text']")
    [attr!=value]
    [attr^=value] 开始
    [attr$=value] 结束
    [attr*=value] 包含
    [s1][s2] 举例:$("div[][][]") 属性取交集

    子元素过滤器
    :nth-child(index/even/odd/equation) 父元素下某个子元素
    :first-child 第一个子元素
    :last-child 最后一个子元素
    :only-child 只能有一个子元素

    表单对象属性过滤器
    :enabled 可用元素
    :disabled 不可用元素
    :checked 被选中的元素,复选框或单选框
    :selected 被选中的元素,下拉框




    表单选择器
    :input 所有input textarea select button元素
    :text 单行文本框
    :password 密码框
    :radio 单选框
    :checkbox 复选框
    :submit 提交按钮
    :image 图像按钮
    :reset 重置按钮
    :button 按钮
    :file 上传域
    :hidden 不可见元素

    注意空格对选择器的影响
    .test :hidden class元素为.test下的隐藏元素
    .test:hidden 隐藏的class为test的元素




    */


    实在有特殊需求的时候,还是从文档中进行查询
  • 相关阅读:
    【leetcode】Binary Search Tree Iterator
    【leetcode】Palindrome Partitioning II
    【leetcode】Best Time to Buy and Sell Stock III
    【leetcode】Best Time to Buy and Sell Stock II
    【leetcode】Longest Consecutive Sequence
    【leetcode】Factorial Trailing Zeroes
    【leetcode】Simplify Path
    【leetcode】Generate Parentheses
    【leetcode】Combination Sum II
    【leetcode】Combination Sum
  • 原文地址:https://www.cnblogs.com/sherrykid/p/5716344.html
Copyright © 2011-2022 走看看