如何使用javascript动态搜索mysql表客户端
我知道如何用静态数据搜索表。我想修改我的脚本来搜索带有动态数据的表,但我不确定该怎么做。我愿意使用Php,但由于我编写的javascript已经可以使用了,我想帮助您使脚本动态化 脚本如何使用javascript动态搜索mysql表客户端,javascript,php,mysql,Javascript,Php,Mysql,我知道如何用静态数据搜索表。我想修改我的脚本来搜索带有动态数据的表,但我不确定该怎么做。我愿意使用Php,但由于我编写的javascript已经可以使用了,我想帮助您使脚本动态化 脚本 <script> function myFunction() { // Declare variables var input, filter, table, tr, td, i; input = document.getElementById("searchData"); filte
<script>
function myFunction() {
// Declare variables
var input, filter, table, tr, td, i;
input = document.getElementById("searchData");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
// Loop through all table rows, and hide those who don't match the search query
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";
}
}
}
}
</script>
函数myFunction(){
//声明变量
var输入、过滤器、表格、tr、td、i;
输入=document.getElementById(“searchData”);
filter=input.value.toUpperCase();
table=document.getElementById(“myTable”);
tr=table.getElementsByTagName(“tr”);
//循环遍历所有表行,并隐藏与搜索查询不匹配的行
对于(i=0;i-1){
tr[i].style.display=“”;
}否则{
tr[i].style.display=“无”;
}
}
}
}
动态表格
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names..">
<table id="myTable">
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Type</th>
<th>Address</th>
<th>Country</th>
<th>Time Zone</th>
</tr>
<?php while($company=mysqli_fetch_array($result)){ ?>
<tr>
<td data-th="ID"><?=$company['id'];?></a></td>
<td data-th="Name"><?=$company['title'];?></td>
<td data-th="Description"><?=$company['description'];?></td>
<td data-th="Type"><?=$company['type'];?></td>
<td data-th="Address"><?=$company['address'];?></td>
<td data-th="Country"><?=$company['country'];?></td>
<td data-th="Time Zone"><?=$company['timezone'];?></td>
</tr>
<?php };?>
</table>
身份证件
名称
描述
类型
地址
国家
时区
您可以尝试这样做:input=document.getElementById(“searchData”);我认为是:input=document.getElementById(“myInput”)@安德烈·罗德里格斯:谢谢,但是这个插件似乎已经过时了,不再维护了。我正在尝试它现在,它不工作,加上该网站不再存在。