jQuery 选择器总结

jQuery Selectors

Basics

$('code')
$('#myid')
$('.myclass')
$('*')
$('code, #myid, .myclass')

Hierarchy

$('div code')
$('li > ul')
$('strong + em') /后面一个/
$('strong ~ em') /后面的/

Basic Filters

$('li:first')
$('li:last')
$('li:not(li:first)')
$('li:even')
$('li:odd')
$('li:eq(1)')
$('li:gt(2)')
$('li:lt(2)')
$(':header')
$(':animated')

Content Filters

$('li:contains(second-level)')
$(':empty')
$('li:has(a)')
$('p:parent')

Visibility Filters

$(':hidden') //display none
$(':visible') //display not none

Attribute Filters

$('li[class]')
$('a[xxx="self"]')
$('a[rel!="nofollow"]')
$('[class^="my"]')
$('[class$="my"]')
$('a[href*="zip"]')
$('a[rel][href][title="blog"]')

Child Filters

$('li:first-child')
$('li:last-child')
$('li:nth-child(even)')
$('li:nth-child(odd)')
$('li:nth-child(2)')
$('li:nth-child(2n)')
$('code:only-child')

Forms

$(':input')
$(':text')
$(':password')
$(':radio')
$(':checkbox')
$(':submit')
$(':image')
$(':reset')
$(':button')
$(':file')

Form Filters

$('input:enabled')
$(':disabled')
$(':checked')
$(':selected')

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • jQuery 的选择器可谓之强大无比,这里简单地总结一下常用的元素查找方法 $("#myELement") 选择...
    web蜗牛阅读 324评论 0 0
  • 几乎使用 jQuery 方法的时候,第一件事就是选择将要被操作的页面元素,恰好 jQuery 提供了强大的选择器语...
    Paranoid_K阅读 351评论 0 0
  • jQuery很强大,一部分原因是强大在选择器上。。。它能够很轻易地拿到 HTML 元素组或单个元素,然后进行各种进...
    Ke_Wang阅读 442评论 0 6
  • 本篇文章转载过来的,收藏了。原文
    ResearchWorld阅读 137评论 0 0
  • ⊙第一把钥匙 你的责任就是你的方向, 你的经历就是你的资本, 你的性格就是你的命运。 ⊙第二把钥匙: 复杂的事...
    zy张燕阅读 375评论 0 4