• jquery里互为逆过程的方法


    jquery里互为逆过程的方法reverse

    在jquery里,有不少互为逆过程的方法,如parent()与children(),parents()与find(),first()和last()等,这些联合起来有助于理解。

    一 children()和parent()

      这是一对遍历dom的jquery方法,这两个方法只查找元素的上一级或者下一级,接受selector参数。不会继续向上或者向下查找。eg:

    html:

    <div>grandfather
      <div>parent
        <div id='self'>self
          <div id="this">this</div>       
    <div>children          <div>descendants
                <span>a span</span>           
    </div>         </div>       </div>     </div> </div>
    $('#self').children("div")//只会选到children不会选到descendants元素
    $('#self').parent("div")//只会选到parent,不会选到grandfather元素

    二 find()和parents()

    find()接受selector或element参数,parents()接受filter参数

    与上面的两个方法相反,find()和parents()会一直查找到dom文本节点和顶层元素为止,还以上面的结构为例

    $('#self').children("div")//会选到descendants元素
    $('#self').parent("div")//会选到grandfather元素

    三 add()和not()

    add()在jquery选择的列表里增加元素,not()减去元素

    $('#self').children("div").add("span")//将span元素添加到前面的列表之中
    $('#self').find("div").not('#this')//将id为this的元素移出列表
    

      

  • 相关阅读:
    map集合方法。
    正则表达式提取器。
    jmeter使用多台linux进行分布式压测。
    如何配置SSHKey
    为什么要做接口测试?
    npm install -g @angular/cli@latest 失败
    关于Newtonsoft.Json,LINQ to JSON的一个小demo
    mysql循环插入数据、生成随机数及CONCAT函数
    WebApi HTTP Put 405 Method not allowed
    npm install 失败
  • 原文地址:https://www.cnblogs.com/imgss/p/6012686.html
Copyright © 2020-2023  润新知