-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.js
More file actions
32 lines (28 loc) · 918 Bytes
/
search.js
File metadata and controls
32 lines (28 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const navSearch = document.getElementById("navSearch");
let searchSection = document.getElementById("searchSection");
navSearch.addEventListener("input", function () {
searchFunc();
});
function searchFunc() {
//검색창 초기화
const searchSectionUl = searchSection.querySelector("ul");
const searchSectionLi = searchSectionUl.children;
let search1 = [...searchSectionLi];
if (searchSectionLi) {
search1.forEach((element) => {
element.remove();
});
}
//검색창 요소 추출
user.forEach((element) => {
let searchInput = navSearch.value;
const userId = element.id;
const userName = element.name;
if (
(searchInput.length > 0 && userId.includes(`${searchInput}`)) ||
(searchInput.length > 0 && userName.includes(`${searchInput}`))
) {
searchSectionUl.innerHTML += `<li>${element.profile} ${element.id} ${element.name}</li>`;
}
});
}