如果子容器不可见,则隐藏父容器
我正在为此抓狂……
我正在使用 jquery 实时搜索过滤器。效果很好。并允许我使用此代码附加和修改事件。
// live search for items
$('input#live_search').quicksearch('li.menu-item', {
'delay': 300,
'loader': 'span.loading',
'bind': 'keyup click',
'show': function () {
$(this).show();
},
'hide': function () {
$(this).hide();
},
'prepareQuery': function (val) {
return new RegExp(val, "i");
},
'testQuery': function (query, txt, _row) {
return query.test(txt);
}
});
被过滤的列表项是它们自己的无序列表和自己的部分的每个部分。我想说的是关于keyup。如果该特定无序列表中的所有列表项都被隐藏。隐藏整个父容器......
我已经在很多方面接近了。但似乎总是有一个障碍。
有人有什么想法吗?
提前致谢。
HTML 呈现如下:
<section id="calzone" class="menu-category">
<header class="category-header cf">text in here</header>
<ul class="menu-items">
<li class="menu-item even" style="display: list-item; ">
text in here
</li>
<li class="menu-item odd" style="display: none; ">
text in here
</li>
<li class="menu-item even" style="display: none; ">
text in here
</li>
<li class="menu-item odd" style="display: none; ">
text in here
</li>
</ul>
</section>
<section id="appetizer" class="menu-category">
<header class="category-header cf">text in here</header>
<ul class="menu-items">
<li class="menu-item even" style="display: none;">
text in here
</li>
<li class="menu-item odd" style="display: none; ">
text in here
</li>
<li class="menu-item even" style="display: none; ">
text in here
</li>
<li class="menu-item odd" style="display: none; ">
text in here
</li>
</ul>
</section>
I'm pulling my hair out on this one...
I'm using a jquery live search filter. Which works great. And allows me this code to attach and modify events.
// live search for items
$('input#live_search').quicksearch('li.menu-item', {
'delay': 300,
'loader': 'span.loading',
'bind': 'keyup click',
'show': function () {
$(this).show();
},
'hide': function () {
$(this).hide();
},
'prepareQuery': function (val) {
return new RegExp(val, "i");
},
'testQuery': function (query, txt, _row) {
return query.test(txt);
}
});
The list items being filtered are each part of their own unordered list and own section. What I want to say is on keyup. If all of the list items in that particular unordered list are hidden. Hide that entire parent container...
Ive gotten close in so many ways. But there always seems to be a snag.
Does anyone have any ideas?
Thanks in advance.
The HTML renders like this:
<section id="calzone" class="menu-category">
<header class="category-header cf">text in here</header>
<ul class="menu-items">
<li class="menu-item even" style="display: list-item; ">
text in here
</li>
<li class="menu-item odd" style="display: none; ">
text in here
</li>
<li class="menu-item even" style="display: none; ">
text in here
</li>
<li class="menu-item odd" style="display: none; ">
text in here
</li>
</ul>
</section>
<section id="appetizer" class="menu-category">
<header class="category-header cf">text in here</header>
<ul class="menu-items">
<li class="menu-item even" style="display: none;">
text in here
</li>
<li class="menu-item odd" style="display: none; ">
text in here
</li>
<li class="menu-item even" style="display: none; ">
text in here
</li>
<li class="menu-item odd" style="display: none; ">
text in here
</li>
</ul>
</section>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
搜索 LI 以查看它们是否可见,如果不可见则隐藏其部分。
(如果有些可见而有些不可见,则不会隐藏。)
但是当您混合隐藏/显示元素时,您可能不会得到一致的结果:)
Searches the LI's to see if they are visible, if not hide's section.
(Will not hide if some are visible and some are not.)
But when you got mixed hidden/shown elements, you might not get a consistent result :)
应该做你想做的事。
Should about do what you want.