【发布时间】:2021-12-23 06:42:41
【问题描述】:
我正在做一个项目,该项目需要在网站上使用搜索栏来搜索(希望是)JSON 文件。它不一定是 json,但它需要能够存储有关对象的其他信息。这就是我现在拥有的,
function search_animal() {
let input = document.getElementById('searchbar').value
input=input.toLowerCase();
let x = document.getElementsByClassName('room');
//input = the input in the search bar
//x = the list of elements
for (i = 0; i < x.length; i++) {
if (!x[i].innerHTML.toLowerCase().includes(input)) {
x[i].style.display="none";
}
else {
x[i].style.display="list-item";
}
}
}
<input id="searchbar" onkeyup="search_animal()" type="text"
name="search">
我不知道如何在键入时弹出结果,以及如何显示除名称之外具有其他特征的对象
【问题讨论】:
标签: javascript html json search