隐藏/显示包含单词的ul li项目.但只能入住李的子女
Hide/show ul li items that contain a word. But check only in a children of the li
标记:(假设列表中有许多子级,都有相同的标记)
<ul class="notifications messages inbox">
<li class=" unread">
<div class="avatar">
<a href="index.php?userid=94"><img alt="" src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/276073_662982570_5177619_n.jpg"> </a>
</div>
<div class="txt">
<a class="userName" href="index.php?userid=94">Jose ignacio bustamante <span class="date"> - 2012-09-07 13:49:59</span></a>
<div>
<a href="messages.php?conversationid=94" class="msj"><span>Esque esto de querer cargar una conversación por defecto... como usuario no ...</span></a>
</div>
</div>
<span data-id="442" class="close">X</span>
</li>
因此,我试图根据.username标签值(在其中)来过滤这个<li>
元素
/* I have used this before, its a :contains modification to handle uppercase */
$.expr[':'].icontains = function(a, i, m) {
return jQuery(a).text().toUpperCase()
.indexOf(m[3].toUpperCase()) >= 0;
};
$('body').on('keyup','.filterFriends',function(){
$('.inbox li').hide().filter(':icontains("'+this.value+'")').show();
/* How to apply this icontains selector to $('.inbox li').find('.userName') ?? */
});
这有一个问题,我想它检查了整个li,我真的不知道如何在filter()函数中选择.userName类。。
有人能给我看看灯吗?
你可以试试这个:
$('body').on('keyup','.filterFriends',function(){
var li=$('.inbox li').hide();
$('.userName',li).filter(':icontains("'+this.value+'")').parents('li').show();
}
$('body').on('keyup','.filterFriends',function(){
$('.inbox li')
.hide()
.find('.userName')
.filter(':icontains("'+this.value+'")')
.closest('.inbox li')
.show();
});
相关文章:
- 角度的项目列表 ng 重复,ng 单击显示全宽描述
- 我怎样才能重复显示接下来的15个项目
- 隐藏/显示包含单词的ul li项目.但只能入住李的子女
- Javascript中的列表,用于添加和显示所有项目
- 如何在点击时显示ul项目
- 限制ul元素中显示的项目
- 在underscore.js中显示列表中的所有项目(使用Parse.com)
- PHP无法显示带有“”的项目'"在他们身上
- HTML选择,在DOM中选择了正确的选项,但在firefox中显示了错误的项目
- 获取中继器控件ASP.Net中显示的单击项目文本框
- 仅显示具有userid作为子项的项目
- 从项目列表Jquery中仅选择(显示:块)元素
- 首先显示选择最多的项目
- 如果项目不匹配,则显示变量
- 只有一个项目显示在 x 轴 d3 中 - 使用刻度值的序号
- 在 HTML 中将数组的每个项目显示为换行符
- 如何正确使用熨斗可选?像铁页一样使用时,项目显示为null
- Html, javascript:滚动列表框项目-并为每个项目显示提示
- 根据从下拉列表中选择的项目显示ViewBag的属性并发布ID
- 如何向选中的项目显示一个箭头?