[英]How i can select multiple arry in jquery?
Hi guys i need to select the name and event and the email and search in them not just one of them as you can see when i put getElementsByTagName("td")[1]; 嗨,大家好,我需要选择名称和事件以及电子邮件,并在其中进行搜索,而不仅是其中之一,正如我输入getElementsByTagName(“ td”)[1]时所看到的那样。 i have the search in name and when i put getElementsByTagName("td")[2]; 我在名称中进行搜索,当我放置getElementsByTagName(“ td”)[2]; i can search in event but i need to search in all 3 of them just 3 not all of them Thanks for your help :) 我可以在事件中搜索,但我需要在所有3个元素中进行搜索,而只有3个而不是全部都感谢您的帮助:)
<!DOCTYPE html>
<html>
<body>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names..">
<table id="myTable" class="table table-hover table-inverse tablesorter">
<thead>
<tr class="header">
<th>
<input type="checkbox" value="All" id="selectIDs" />
</label>
</th>
<th>Name</th>
<th>Event</th>
<th>Email</th>
<th>Iban</th>
<th>UID</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<% uids.forEach(function(uid){ %>
<tr>
<td><input type="checkbox" class="checkbox" name="productIds" value="<%=uid._id%>"></td>
<td ><%= uid.name %></td>
<td ><%= uid.event %></td>
<td ><%= uid.email %></td>
<td><%= uid.iban %></td>
<td><%= uid.uid %></td>
<td><%= uid.readableDate %></td>
</tr>
<% }) %>
</tbody>
</table>
<p id="demo"></p>
<script>
function myFunction() {
// Declare variables
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
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")[1];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
</body>
</html>
Could you use an array with the 3 elements by row you need, as 您是否可以按需要使用具有按行排列的3个元素的数组,如
let newArray = new Array();
if(tr[i].getElementsByTagName("td")[1]) newArray.push(tr[i].getElementsByTagName("td")[1].innerHTML.toUpperCase());
if(tr[i].getElementsByTagName("td")[2]) newArray.push(tr[i].getElementsByTagName("td")[2].innerHTML.toUpperCase());
if(tr[i].getElementsByTagName("td")[3]) newArray.push(tr[i].getElementsByTagName("td")[3].innerHTML.toUpperCase());
And then do you search in this array : 然后在这个数组中搜索:
if (newArray.filter((e,i) => e.indexOf(filter) > -1).length > 0) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
Or 要么
if (newArray.indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
If you want to check each letter or the full word. 如果要检查每个字母或完整的单词。
Is this better ? 这是否更好 ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.