jQuery选择器汇总

首先介绍一下prototype
Prototyppe
是最早成型的js库之一,对js的内置对象(String对象、Array对象等)做了大量的扩展。现在还有很多项目使用Prototype 。
Prototype可以看做是把很多有用的JavaScript的方法组合在一起而形成的JavaScript库。使用者可以在需要的时候随时把极端代码抽出来放进自己的脚本里

现在总结使用jQuery语法
jQuery选择器(基本、表单、层次、过滤)

基本选择器  通过id class 和标签名来查找DOM元素。

#id    .class     element      *       selector1,selector2,...selectorN




过滤选择器  过滤规则选择DOM元素(与CSS中的伪类选择器语法相同,都以:开头)

:first                    $("div:first")                           选取所有<div>元素中第一个<div>元素
:last                     $("div:last")                            选取所有<div>元素中最后一个<div>元素      
:not(selector)   $("input:not(.myclass)")     选取class不是myclass的<input>元素          
:even                  $("input:even")                     选取索引是偶数的<input>元素
:odd                    $("input:odd")                       选取索引是奇数的<input>元素
:eq(index)         $("input:eq(1)")                     选取索引等于1的<input>元素
:gt(index)          $("input:gt(1)")                     选取索引大于1的<input>元素
:lt(index)           $("input:lt(1)")                       选取索引小于1的<input>元素
:header              $(":header" )                          选取网页中所有的<h1> <h2>....
:animated         $("div:animated")                 选取正在执行动画的div元素
:focus                 $(":focus")                               选取当前获取焦点的元素                
:hidden              $(":hidden")                            选取所有不可见的元素
:visible                $("div:visible")                       选取所有可见的div元素
:contains            $("div:contains('wo')")
:empty                $("div:empty")
:has(selector)    $("div:has(p)")
:parent                $("div:parent")

属性过滤选择器
[attribute]                        拥有属性            
[attribute=value]           等于
[attribute!=value]          不等于
[attribute^=value]         以开始
[attribute$=value]          以结束
[attribute*=value]          包含
[attribute|=value]           等于或为前缀
[attribute~=value]         用空格分隔的值中包含 
[attribute1][attribute2][attributeN]


子元素过滤选择器  p44
:nth-child(index/even/odd/equation)    每个父元素下第index个子元素或者奇偶元素
:first-child                                                       每个父元素的第一个子元素
:last-child                                                        每个父元素的最后一个子元素
:only-child                                                      父元素中只有一个元素的





表单选择器  选择表单的某个或某类型的元素
:input
:text
:password
:radio
:checkbox
:submit
:image
:reset
:button
:file
:hidden
:enabled
:disabled
:checked
:selected


层次选择器  通过层次关系获取元素

$("ancestor descendant")      选取ancestor元素里面的descendant(后代)元素
$("parent>child")                     选取parent元素下的child(子)元素
$("prev+next")                          选取紧接在prev元素后的next元素。等价next()          $(".one+div")=$(".one").next("div")
$("prev~siblings")                    选取prev元素之后的所有siblings元素
$("#prev~div")=$("#prev").nextAll("div")                     







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值