gpt4 book ai didi

javascript - 我希望表格在搜索时显示隐藏行并在删除输入时隐藏它们?

转载 作者:行者123 更新时间:2023-11-28 05:54:28 25 4
gpt4 key购买 nike

它不显示 .hidden 类,当我搜索时它会显示它,但问题是当我删除输入时它不会消失......

如何解决这个问题,以便当我开始删除输入时 .hidden 类消失?

这是我的源代码:HTML:

<input id="filter" type="text" class="form-control" placeholder="Datumu, Naslovu, Propovedniku">

<table class="table table-striped">
<thead>
<tr>
<th>Date</th>
<th>Title</th>
<th>Something</th>
<th>Options</th>
</tr>
</thead>
<tbody class="searchable">
<tr>
<td>12/06/16</td>
<td>Example</td>
<td>Janko Tomas</td>
<td>Video</td>
</tr>
<tr>
<td>GBP</td>
<td>Pound</td>
<td></td>
<td>Active</td>
</tr>
<tr>
<td>GEL</td>
<td>Georgian Lari</td>
<td><span class="glyphicon glyphicon-ok"></span>
</td>
<td>Active</td>
</tr>
<tr>
<td>USD</td>
<td>US Dollar</td>
<td></td>
<td>Active</td>
</tr>
<tr class="hidden">
<td>USD</td>
<td>US Dollar</td>
<td></td>
<td>Active</td>
</tr>
</tbody>
</table>

CSS:

#section{
width: 80%;
margin: auto;
}

.sub-section{
width: 100%;
margin: auto;
position: relative;
}

.table{
width: 100%;
margin: auto;
background-color: white;
}

thead{
background-color: #333;
color: white;
margin: 0;
}

thead tr th{

font-weight: normal;
padding-top: 5px;
padding-bottom: 5px;
}
thead tr{
margin: 0;
padding: 0;
}

.hidden{
display: none;
}

最后是 JQUERY:

$(document).ready(function () {

(function ($) {

$('#filter').keyup(function () {

var rex = new RegExp($(this).val(), 'i');
$('.searchable tr').hide();
$('.searchable tr').filter(function () {
return rex.test($(this).text());
}).show();
$('.hidden').filter(function () {
return rex.test($(this).text());
}).show();
})
}(jQuery));
});

最佳答案

检查一下,我认为这对您有帮助

$(document).ready(function () {

(function ($) {

$('#filter').keyup(function () {

var rex = new RegExp($(this).val(), 'i');
$('.searchable tr').hide();
$('.searchable tr').filter(function () {
return rex.test($(this).text());
}).show();
if($(this).val()!=""){
$('.hidden').filter(function () {
return rex.test($(this).text());
}).show();
}
else{
$('.hidden').hide();
}



})





}(jQuery));

});
 <style>
#section{
width: 80%;
margin: auto;
}

.sub-section{
width: 100%;
margin: auto;
position: relative;
}

.table{
width: 100%;
margin: auto;
background-color: white;
}

thead{
background-color: #333;
color: white;
margin: 0;
}

thead tr th{

font-weight: normal;
padding-top: 5px;
padding-bottom: 5px;
}
thead tr{
margin: 0;
padding: 0;
}

.hidden{
display: none;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="filter" type="text" class="form-control" placeholder="Datumu, Naslovu, Propovedniku">

<table class="table table-striped">
<thead>
<tr>
<th>Date</th>
<th>Title</th>
<th>Something</th>
<th>Options</th>
</tr>
</thead>
<tbody class="searchable">
<tr>
<td>12/06/16</td>
<td>Example</td>
<td>Janko Tomas</td>
<td>Video</td>
</tr>
<tr>
<td>GBP</td>
<td>Pound</td>
<td></td>
<td>Active</td>
</tr>
<tr>
<td>GEL</td>
<td>Georgian Lari</td>
<td><span class="glyphicon glyphicon-ok"></span>
</td>
<td>Active</td>
</tr>
<tr>
<td>USD</td>
<td>US Dollar</td>
<td></td>
<td>Active</td>
</tr>
<tr class="hidden">
<td>USD</td>
<td>US Dollar</td>
<td></td>
<td>Active</td>
</tr>
</tbody>
</table>

关于javascript - 我希望表格在搜索时显示隐藏行并在删除输入时隐藏它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37817682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com