๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์ดํŽ™ํŠธ

์„œ์น˜ ์ดํŽ™ํŠธ 4

by Youcodein 2022. 9. 29.
728x90
๋ฐ˜์‘ํ˜•

์„œ์น˜ ์ดํŽ™ํŠธ ๋งŒ๋“ค๊ธฐ2

javascript๋ฅผ ์ด์šฉํ•˜์—ฌ ์„œ์น˜ ์ดํŽ™ํŠธ๋ฅผ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ์—ด์‹ฌํžˆ ๊ณต๋ถ€ํ•˜์„ธ์š”!


์„œ์น˜ ์ดํŽ™ํŠธ2

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ

์ถ”ํ›„ ์ถ”๊ฐ€ ์˜ˆ์ •

//์„ ํƒ์ž
const searchBox = document.querySelector(".search__box input");            //๊ฒ€์ƒ‰ ์˜์—ญ
const searchList = document.querySelectorAll(".search__list ul li"); //๋ชฉ๋ก ๋ฆฌ์ŠคํŠธ
const searchInfo = document.querySelector(".search__info .num")     //์ „์ฒด ๊ฐฏ์ˆ˜


//์†์„ฑ ๊ฐฏ์ˆ˜ ์„ค์ •ํ•˜๊ธฐ

// for(let i=1; i<=searchList.length; i++){
//     const searchInfo = document.querySelector(".search__info .num")
//     searchInfo.innerHTML = i;
// };

searchInfo.textContent = searchList.length;


//
searchBox.addEventListener("keyup", () => {
    const searchWord = searchBox.value;     //์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ํ‚ค์›Œ๋“œ
    searchList.forEach(el => {
        const cssName = el.dataset.name;

        if (cssName.includes(searchWord)) {
            el.classList.remove("hide");
        } else {
            el.classList.add("hide");
        }
    });
});
728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€