html - 过滤前隐藏引导表
问题描述
我有一个引导 html 表。过滤用于现场。如何确保在过滤开始之前隐藏表格内容?过滤脚本和html表:
$(document).ready(function(){
$("#surname").on("keyup", function () {
var value = $(this).val().toLowerCase();
$("#table tr").filter(function () {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});
</script>
<table class="table" id="table">
<thead class="thead-light">
<tr>
<th></th>
<th class="text-center" scope="col">Guest</th>
<th class="text-center" scope="col">Org</th>
解决方案
Bootstrap v4用于d-none
将任何内容设置为“显示:无”。
在每个上设置每个<tr class="d-none">
,默认情况下它们将被隐藏。在您的代码中,就在您过滤完所有内容之后,让我们使用 jquery 再次显示它们(未测试):
/* ... */
$("#table tr").filter(function () {
const show = $(this).text().toLowerCase().indexOf(value) > -1;
if (show) {
$(this).removeClass('d-none');
}
});
推荐阅读
- javascript - 更改导航栏中的图标折叠引导程序
- android - Android Firestore 查询分页 FirebaseFirestoreException: INVALID_ARGUMENT
- ios - 如何在应用程序处于后台时检测用户图库中的更改 - iOS
- r - 删除新添加的列时如何恢复到旧数据框?
- c++ - 通过在 C++ Builder 中编写新函数来转换代码
- python-3.x - 无论在 Django 中更改模板(或发生其他外部问题)如何,在后台提取大型 zip 文件的最佳方法是什么?
- javascript - 在图表中显示数据库中的项目
- javascript - 错误:NotAllowedError:当前上下文中用户代理或平台不允许该请求
- c# - 如何在 IActionResult Asp.net WebAPI 中传递多个参数(对象)
- java - 线程解释-每次运行代码时都有不同的答案