jQuery学习笔记:9类选择器的使用

2019-03-2209:51:52WEB前端开发Comments1,554 views字数 1562阅读模式

一.基本选择器:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10284.html

  • #id   :选择给定ID名的元素 如:$("#id1")为选择id为id1的元素
  • .class   :选择给定类名的元素
  • element   :选择给定元素名的所有原色
  • *  :匹配所有元素
  • selector1,selector2,......   :选择这些名称的元素,以逗号隔开,可以是类或id名

二.层次选择器:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10284.html

  • $("ancestor  descendant") :选择ancestor元素下的所有descendant(后代)元素
  • $("parent>child") :选择parent下的所有child(子)元素
  • $('prev+next') :选择紧跟prev后面的第一个next元素
  • $('prev~siblings') :选择prev后面的所有siblings元素

$('prev+next') 和$(.prev).next("next")作用一样文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10284.html

$('prev~siblings')和$(.prev).nextAll("siblings")作用一样文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10284.html

三.过滤选择:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10284.html

  • :first    选择第一个元素  如:$("div:first")为选择第一个div元素
  • :last   选择最后一个元素
  • :not(selector)  选择不是selector的元素
  • :even  选择偶数索引的元素
  • :odd  选择所有奇数索引的元素
  • :eq(index)  选择索引等于index的元素
  • :gt(index)  选择索引大于index的元素
  • :lt(index)  选择索引小于index的元素
  • :header  选择所有<H>元素
  • :animanted  选择所有动画元素

四。内容过滤:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10284.html

  • :contains(text)  选择含有text文本的元素 如:$("div:contains('hello')")为选择含有hello字符的div元素
  • :empty 选择所有不含字符的元素
  • :has(selector)  选择含有selector元素的元素
  • :parent 选择含有子元素的元素

五。可见性过滤:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10284.html

  • :hidden 选择所有可见元素
  • :visible 选择所有不可见元素

六。属性过滤:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10284.html

  • [attribute]  选择拥有此属性的元素 如$("div[id]")选择包含id属性的div元素
  •  [attribute=value] 选择attribute属性等于value值的元素
  •  [attribute!=value]  选择attribute属性不等于value值的元素
  •  [attribute^=value]   选择attribute属性等于value值的元素
  •  [attribute$=value]  选择attribute属性值以value值开始的元素
  •  [attribute*=value]  选择attribute属性值含有value值的元素
  • [selector1][selector2]....满足这些条件的元素(组合)

七。子元素过滤选择器文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10284.html

  • :nth-child(index/even/odd/eqation)选择父元素下的[索引/偶/奇]的子元素
  • :first-child 选择父元素的第一个子元素
  • :last-child选择父元素的最后一个子元素
  • :only-child 选择父元素下是唯一的子元素

八。表单属性过滤文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10284.html

  • :enabled 选择所有可见元素 如:$("#form1:enabled")是选择表单id为form1的所有可以用元素
  • :disable 选择所有不可见元素
  • :checked 选择所有被选择的元素
  • :selected 选择所有被选中的选项元素

九.表单对象过滤文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10284.html

  • :input  选择所有<input><textarea><select><button>元素
  • :text 选择所有单行文本款,下面的都是这个格式
  • :password
  • :radio
  • :checkbox
  • :submit
  • :image
  • :reset
  • :button
  • :file
  • :hidden

 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10284.html

文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/10284.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/gcs/10284.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定