我创建了一个手动搜索功能,可以在用户输入时显示结果。这里是小提琴:https://jsfiddle.net/rtq4jfuq/1/jQuery如何统计被隐藏的元素
这里是HTML
<script src='https://code.jquery.com/jquery-3.2.1.min.js'></script>
<input style='width: 300px;' placeholder='search' id='search'>
<table border='1'>
<tr>
<th>Name</th>
</tr>
<tr class='names'>
<td>Bob</td>
</tr>
<tr class='names'>
<td>Ted</td>
</tr>
<tr class='names'>
<td>Steve</td>
</tr>
<tr class='names'>
<td>Sven</td>
</tr>
<tr class='names'>
<td>Magnus</td>
</tr>
</table>
这里是脚本
$(document).ready(function() {
$("#search").keyup(function(){
var query = $(this).val();
$(".names").each(function(){
var n = $(this).children("td").html();
if (n.toUpperCase().includes(query.toUpperCase())) {
$(this).css("display", "");
}
else {
$(this).css("display", "none");
}
});
});
});
我想显示一条消息,一旦有没有显示的行,但我怎么检查没有行显示?
已尝试$(element).is(“:visible”)或$(element).css('display')==='none'? –