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.
我真的不明白为什么会这样:
$('.myitem').next('.exampleClass').css('display','none');
给我
[]
(在 chrome 控制台中)和
$(".myitem").parent().css('display','none');
确实有效,并给了我 html 代码,实际上做了我想做的事情
[]总的来说,chome是什么意思?null?
null
基本上我试图找到父母<li>并隐藏它,然后找到下一个<li>并显示它。
<li>
[] 是一个空数组。许多 jQuery 函数 ruturn 一个 jQuery 对象数组。您的 jQuery 函数没有找到任何与“.exampleClass”匹配的内容,因此它返回了一个空数组。
如果下一个兄弟不是 .exampleClass,它可以返回空。
我会使用这样的东西:
$('.myitem').nextAll('.exampleClass').first().css('display','none');