有人可以解释一下为什么要更换以下内容
$('.post_title a').hover(function () {
$(this).parent().parent().parent().parent().find(".post_footer").toggleClass('footer_border')
});
Run Code Online (Sandbox Code Playgroud)
同
$('.post_title a').hover(function () {
$(this).closest(".post_footer").toggleClass('footer_border')
});
Run Code Online (Sandbox Code Playgroud)
不起作用?
查看文档.closest().它指出:
给定一个表示一组DOM元素的jQuery对象,该
.closest()方法在DOM树中搜索这些元素及其祖先,并从匹配元素构造一个新的jQuery对象.的.parents()和.closest()方法类似,因为它们都遍历DOM树.
由于您要查找的元素不是链接的祖先,因此它不起作用.要实现您的需求,您可以使用它:
$(this).parents().next('.post_footer').eq(0).toggleClass('footer_border');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7474 次 |
| 最近记录: |