Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个标记:
<ul class=container> <li rec=1> <div> <div> <div>i'm here</div> </div> </div> </li> </ul>
现在我在 div 元素(“我在这里”),我怎样才能获得对 li 的引用?我试过div.parent("li");但没用..
div.parent("li");
利用
closest("li")
而不是父母http://docs.jquery.com/Traversing/closest 父母只获得直接父母。
parent用于获取元素的唯一直接前导,在您的情况下是div.
parent
div
你应该使用parentsor closest:
parents
closest
div.parents("li");