Javascript 使两个筛选表下拉列表同时工作
我正试图使位置过滤器下拉列表和类别下拉列表同时工作,以便根据位置和类别显示表值,但用于此的displayDate函数不起作用。以下是网站: 以下是该页面的代码:Javascript 使两个筛选表下拉列表同时工作,javascript,filter,html-table,dropdown,Javascript,Filter,Html Table,Dropdown,我正试图使位置过滤器下拉列表和类别下拉列表同时工作,以便根据位置和类别显示表值,但用于此的displayDate函数不起作用。以下是网站: 以下是该页面的代码: <div class="search-box"> <input class="search-txt" type="text" name="" id="searchList" onkeyup="searchF
<div class="search-box">
<input class="search-txt" type="text" name="" id="searchList" onkeyup="searchFunction()" placeholder="Search by name..."> <a class="search-btn" href="#">
<i class="fas fa-search"></i>
</a>
</div>
<select id="mylist" class='form-control'>
<option value="">Filter by location</option>
<option value="Remote">Remote</option>
<option value="Alabama">Alabama</option>
<option value="Alaska">Alaska</option>
<option value="Arizona">Arizona</option>
</select>
<select id="categorylist" class='form-control'>
<option value="">Filter by category</option>
<option value="Computer Science">Computer Science</option>
<option value="Science">Science</option>
<option value="Political Science">Political Science</option>
<option value="Business/Marketing">Business/Marketing</option>
<option value="Music">Music</option>
<option value="Art">Art</option>
<option value="All STEM fields">All STEM fields</option>
</select>
<button onclick="displayDate()">Submit</button>
<table id="show" style="padding:30px; width:90%;" class="internshipInfo">
<thead>
<tr>
<th>Internship name</th>
<th>Internship location</th>
<th>Internship category</th>
<th>Internship link</th>
<th>Internship deadline</th>
</tr>
</thead>
</table>
<script>
function searchFunction() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("searchList");
filter = input.value.toUpperCase();
table = document.getElementById("show");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
<script>
function displayDate() {
var input, input2 filter, filter2, table, tr, td, i, test;
input = document.getElementById("mylist");
input2 = document.getElementById("categorylist");
filter = input.value.toUpperCase();
filter2 = input2.value.toUpperCase();
table = document.getElementById("show");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[1];
test = tr[i].getElementsByTagName("td")[2]
if (td) {
if (td.toUpperCase() === filter && test.toUpperCase() === filter2) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
按位置筛选
遥远的
阿拉巴马州
阿拉斯加州
亚利桑那州
按类别筛选
计算机科学
科学类
政治学
商业/营销
音乐
艺术
所有茎田
提交
实习名称
实习地点
实习类别
实习环节
实习期限
函数searchFunction(){
var输入、过滤器、表格、tr、td、i、TXT值;
输入=document.getElementById(“搜索列表”);
filter=input.value.toUpperCase();
table=document.getElementById(“显示”);
tr=table.getElementsByTagName(“tr”);
对于(i=0;i-1){
tr[i].style.display=“”;
}否则{
tr[i].style.display=“无”;
}
}
}
}
函数displayDate(){
var输入,输入2滤波器,滤波器2,表,tr,td,i,测试;
输入=document.getElementById(“mylist”);
input2=document.getElementById(“categorylist”);
filter=input.value.toUpperCase();
filter2=input2.value.toUpperCase();
table=document.getElementById(“显示”);
tr=table.getElementsByTagName(“tr”);
对于(i=0;i
欢迎来到堆栈溢出。感谢您发布您的代码-请确定哪些功能出现故障,预期结果是什么,如何重现,等等,非常混乱。你不知道在这250条线路中,哪些线路给你带来了麻烦?否则,您将只询问有用的部分,而不是整个html页面