【发布时间】:2021-12-26 13:07:10
【问题描述】:
HTML 和 JavaScript
$("#btn10").click(function() {
$(".search-boxes").toggle()
}),
$("#comfilter").on("keyup", function() {
var value = $(this).val().toLowerCase();
$("#communication_mode_table tr").each(function(index) {
if (index !== 1) {
$row = $(this);
var id = $row.find("td:first").text().toLowerCase();
if (id.indexOf(value) == -1) {
$row.hide();
} else {
$row.show();
}
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="btn10"><i class="fa fa-filter"></i> Filter</button>
<table id="communication_mode_table" class="table table-bordered table-hover">
<thead>
<tr>
<th>Nature Of Fault</th>
<th>Push Notification
<input type='checkbox' name='all_push' id='all_push' class='all_push' </th>
<th>SMS
<input type='checkbox' name='all_sms' id='all_sms' class='all_sms' />
</th>
<th>Call
<input type='checkbox' name='all_call' id='all_call' class='all_call' />
</th>
<th>Email
<input type='checkbox' name='all_email' id='all_email' class='all_email' />
</th>
</tr>
<tr class="search-boxes " style="display: none;">
<th>
<input id="comfilter" type="text" class="form-control" />
</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody> </tbody>
</table>
为什么我的表格标题在键入搜索框时消失了?
如果我放了
if(index !== 0),搜索框本身就从屏幕上消失了,谁能帮我找到解决办法?
是否有任何替代解决方案可用于实现此过滤器?
【问题讨论】:
标签: javascript html jquery search