ITPub博客

首页 > IT职业 > IT生活 > jQuery 选择器

jQuery 选择器

IT生活 作者:castlight 时间:2021-09-09 09:50:10 0 删除 编辑

         选择器1. 基本选择器 标签名:a p h2 body id: class: p a#id.class: 拥有class类,id为id,包含在p内的链接2. 子选择器 >: 直接子节点 ul.mylist > li > a +:紧邻兄弟 -:非紧邻兄弟  3. 容器选择器 li:has(a): 含有a的所有li 只支持一层嵌套:div.not(li:has(a)) 不包含 拥有的li 的所有div 不支持: foo.not(li:has(bz:eq(2)))  4. 特性选择器 contain: form[method] 具有显示method声明的form 匹配:div[title=test] start with: a[href^=http://] end with:a[href$=jquery.com] 任何部位包含:a[href*=jquery.com] 5. 位置选择 第一个:first a:first 奇数:odd p:odd 偶数:even p:even first-child: li:first-child 列表第一项 last-child: li:last-child 列表最后一项 6. jquery选择器 元素::button :checkbox :file header :image :input :parent :password :radio :reset :submit :text 状态::checked :disabled :enabled :hiden :selected :visible 属性::contains(foo)包含文本foo :not :checkbox:checked:enabled:已选择已启用的checkbox input:not(:checkbox):非复选框的input 操作包装集1. $('input[alt]')[0]  $('input[alt]').get(0)   var allLabeledButtons=$('label+button').get();2. index: 返回数组中的下标 $('img').index($('img#findMe')[0])3. add: ${'img[alt]'}.add($('img[title]'))4. not: ${'img[title]'}.not('[title*=puppy]')5. filter:传入一个函数,对包装集中每个元素应用,如果返回false删除该元素 $('td').filter(function(){returnn this.innerHTML.match(/^d+$)}) 过滤不删除:$('img').addClass('seeThrough').filter('[title*=dog]').addClass('thickBorder')6. slice(begin,end): 子集,end 不被包含7. 利用关系,返回新包装集,原始包装集不变 children() parent nex pre8. find: 返回新包装集,包含于选择器匹配的所有元素。注意!!:原始包装集的后代与选择表达式匹配也会包含在内9. end: 链内调用,返回上一包装集

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1470/viewspace-2813160/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    102
  • 访问量
    1240