以下是我的代码,其工作原理如下: 如果某人检查了一个复选框(或多个复选框),则代码会过滤并仅显示无序列表中的正确结果。
我想做什么:如果没有结果,它应该显示特定的无结果发现消息,例如:“哎呀,没有找到结果”。
你可以帮我这个吗?感谢您的帮助。代码:
$(document).ready(function() {
$('.filtered li').hide();
$("[name='filter']").change(function() {
$('.filtered li').show();
$("[name='filter']:checked").each( function() {
var tag=$(this).val();
$('.filtered li')
.children(".tags:not(:contains('"+tag+"'))")
.parent()
.hide();
});
});
});
HTML部分:
<input id="filter1" name="filter" size="40"/ type='checkbox' value=filter1>filter1
<input id="filter2" name="filter" size="40"/ type='checkbox' value=filter2>filter2
<input id="filter3" name="filter" size="40"/ type='checkbox' value=filter3>filter3</br>
<input id="filter4" name="filter" size="40"/ type='checkbox' value=filter4>filter4
<input id="filter5" name="filter" size="40"/ type='checkbox' value=filter5>filter5
<input id="filter6" name="filter" size="40"/ type='checkbox' value=filter6>filter6
<input id="filter7" name="filter" size="40"/ type='checkbox' value=filter7>filter7
<input id="filter8" name="filter" size="40"/ type='checkbox' value=filter8>filter8
<input id="filter9" name="filter" size="40"/ type='checkbox' value=filter9>filter9</br>
<input id="filter10" name="filter" size="40"/ type='checkbox' value=filter10>filter10
<input id="filter11" name="filter" size="40"/ type='checkbox' value=filter11>filter11
<input id="filter12" name="filter" size="40"/ type='checkbox' value=filter12>filter12</br>
<input id="filter13" name="filter" size="40"/ type='checkbox' value=filter13>filter13
<input id="filter14" name="filter" size="40"/ type='checkbox' value=filter14>filter14
<input id="filter15" name="filter" size="40"/ type='checkbox' value=filter15>filter15
<input id="filter16" name="filter" size="40"/ type='checkbox' value=filter16>filter16
<input id="filter17" name="filter" size="40"/ type='checkbox' value=filter17>filter17</br>
<input id="filter18" name="filter" size="40"/ type='checkbox' value=filter18>filter18
<input id="filter19" name="filter" size="40"/ type='checkbox' value=filter19>filter19
<input id="filter20" name="filter" size="40"/ type='checkbox' value=filter20>filter20</br>
<br><br>
<div id="HELP" class="filtered">
<ul>
<li>1
<span class="tags">filter1 filter5 filter7 filter9</span>
</li>
<li>2
<span class="tags">filter2 filter15 filter17 filter19</span>
</li>
<li>3
<span class="tags">filter4 filter5 filter13 filter12</span>
</li>
<li>4
<span class="tags">filter7 filter14 filter18 filter19</span>
</li>
<li>5
<span class="tags">filter9 filter11 filter14 filter20</span>
</li>
<li>6
<span class="tags">filter20 filter10 filter16 filter8</span>
</li>
<li>7
<span class="tags">filter5 filter7 filter12 filter17</span>
</li>
</ul>
答案 0 :(得分:0)
var results = $('.filtered li').children(".tags:not(:contains('"+tag+"'))").length;
if(results < 1){
// show some no results message
}