Home  >  Q&A  >  body text

不明白find与​child的区别。什么情况下find与children等价?

小白小白2882 days ago975

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-09-30 23:02:51

    I don’t understand the difference between find and child. Under what circumstances is find equivalent to children? -PHP Chinese website Q&A-I don’t understand the difference between find and child. Under what circumstances is find equivalent to children? -PHP Chinese website Q&A

    Please watch and learn.

    reply
    0
  • 迷茫

    迷茫2016-12-20 09:12:00

    这种情况下

    <div class="div">
        <p>pXXXXXp</p>
        <p>pXXXXXp</p>
        <p>pXXXXXp</p>
        <p>pXXXXXp</p>
    <div>
     
    $(".div").find("p") == $(".div").children()

    find()用于查找后代元素,children()用于查找子代元素,显然,后代元素就包含了子代元素,因此find的查找范围比children大,你只需在find()括号里面加入适当的选择器就可以实现children()的功能了。

    reply
    2
  • Cancelreply