如何解决jQuery过滤表单元格
| 我需要过滤我的表,以便它仅使用所需的最小行数,例如,如果表维度的宽度为5列,则具有12个结果的过滤器结果应具有3行。我现在所拥有的仅能过滤掉行的列,而使表中的行过多。 jQuery的:$(\"#filter\").keyup(function(){
// Retrieve the input field text and reset the count to zero
var filter = $(this).val(),count = 0;
// Loop through the comment list
$(\"td\").each(function(){
// If the list item does not contain the text phrase fade it out
if ($(this).text().search(new RegExp(filter,\"i\")) < 0) {
$(this).hide();
// Show the list item if the phrase matches and increase the count by 1
} else {
$(this).show();
count++;
}
});
// Update the count
var numberItems = count;
$(\"#filter-count\").text(\"Number of Comments = \"+count);
});
$i++;
解决方法
这行不通。最好使用固定宽度和高度的div而不是td,然后将float:留给它们。然后,答案将始终显示为整行,最后一行可能除外。
您可以使用td \'s,但这要困难得多。您必须先获取td \,然后用tr \'s重建整个表,然后再将td \放回原处。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。