gpt4 book ai didi

javascript - 如何根据下拉选择的值过滤 html 表?

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

我有一个 html 表,其中包含一些数据行,其中有一列名为状态。他们有三种状态,正在进行中,待办,已完成。我在顶部有一个下拉菜单。下拉列表包含 Any、In progress、To do、Completed。如何根据选定的下拉值加载数据。下面我附上了我的页面图片。

enter image description here

我的代码在下面。表格数据来自数据库。

<div class="table-wrapper">
<div class="table-title">
</div>
<div class="table-filter">
<div class="row">
<div class="col-sm-3">
<div class="show-entries">
<span>Show</span>
<select class="form-control">
<option>5</option>
<option>10</option>
</select>
<span>entries</span>
</div>
</div>
<div class="col-sm-9">
<div class="filter-group">
<label>Status</label>
<select class="form-control">
<option>Any</option>
<option>Completed</option>
<option>In Progress</option>
<option>To Run</option>
</select>
</div>
<span class="filter-icon"><i class="fa fa-filter"></i></span>
</div>
</div>
</div>
<form method="post" action="activeInactive.php">
<table class="paginated table table-striped table-hover">
<thead>
<tr>
<th>Test Name</th>
<th>Created By</th>
<th>Last updated</th>
<th>Test status</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="test_table">

<?PHP

$test_access = 0;
while($row = mysqli_fetch_array($tests_under_user)){
echo '<td width=250px; title="'.$testName.'"><a href="">'.$row['name'].'</a></td>';
echo '<td title="'.$row['created'].'">'.$row['created'].'</td>';
echo '<td title="'.$row['edited'].'">'.$row['edited'].'</td>';
echo '<td>In Progress</td>';
echo '<td>';
echo '<a href="" class="edit" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Edit">&#xE254;</i></a>';
echo '<a href="" class="delete" name="delete" data-toggle="modal" Onclick="return ConfirmDelete()"><i class="material-icons" data-toggle="tooltip" title="Delete">&#xE872;</i></a>';
echo '<a href="" class="copy" name="copy" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Copy" style="color: #2874A6">file_copy</i></a>';
echo '</td>';
}
?>
</tbody>
</table>
</form>
</div>

最佳答案

这可能对您有所帮助。

Visit here to try filtering with select tag.

function myFunction() {
var input, filter, table, tr, td, i;
input = document.getElementById("mylist");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
* {
box-sizing: border-box;
}

#myInput {
background-image: url('/css/searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
width: 100%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}

#mylist {

background-position: 10px 10px;
background-repeat: no-repeat;
width: 100%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}

#myTable {
border-collapse: collapse;
width: 100%;
border: 1px solid #ddd;
font-size: 18px;
}

#myTable th, #myTable td {
text-align: left;
padding: 12px;
}

#myTable tr {
border-bottom: 1px solid #ddd;
}

#myTable tr.header, #myTable tr:hover {
background-color: #f1f1f1;
}
<h2>My Customers</h2>
<select id="mylist" onchange="myFunction()" class='form-control'>
<option>A</option>
<option>b</option>
<option>c</option>
</select>


<table id="myTable">
<tr class="header">
<th style="width:60%;">Name</th>
<th style="width:40%;">Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Germany</td>
</tr>
<tr>
<td>Berglunds snabbkop</td>
<td>Sweden</td>
</tr>
<tr>
<td>Island Trading</td>
<td>UK</td>
</tr>
<tr>
<td>Koniglich Essen</td>
<td>Germany</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Italy</td>
</tr>
<tr>
<td>North/South</td>
<td>UK</td>
</tr>
<tr>
<td>Paris specialites</td>
<td>France</td>
</tr>
</table>

关于javascript - 如何根据下拉选择的值过滤 html 表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51515778/

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