๊ด€๋ฆฌ ๋ฉ”๋‰ด

Hey Tech

JavaScript์™€ HTML์„ ํ™œ์šฉํ•œ ๋ฒ„ํŠผ ํด๋ฆญ ํšŸ์ˆ˜ ์ถœ๋ ฅ ์˜ˆ์ œ ๋ณธ๋ฌธ

SW ๊ฐœ๋ฐœ/Vanilla JS

JavaScript์™€ HTML์„ ํ™œ์šฉํ•œ ๋ฒ„ํŠผ ํด๋ฆญ ํšŸ์ˆ˜ ์ถœ๋ ฅ ์˜ˆ์ œ

Tony Park (ํ† ๋‹ˆ) 2021. 12. 15. 16:06
728x90
๋ฐ˜์‘ํ˜•

๐Ÿ”ฅ ๋ชฉํ‘œ

JavaScript์™€ HTML์„ ํ™œ์šฉํ•˜์—ฌ ๊ฐ„๋‹จํ•œ Interactive Web ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•ด ๋ณธ๋‹ค.

์˜ˆ์ œ

๊ฐ„๋‹จํ•œ ์˜ˆ์ œ๋ฅผ ์‹ค์Šตํ•ด ๋ด…๋‹ˆ๋‹ค. HTML์„ ํ™œ์šฉํ•ด ๋ฒ„ํŠผ UI๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์›น์— ์ถœ๋ ฅํ•˜๊ณ , JavaScript๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉ์ž๊ฐ€ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋Š” ๊ฒƒ์„ ๊ฐ์ง€ํ•˜์—ฌ ํด๋ฆญ ํšŸ์ˆ˜๋ฅผ ์‹ค์‹œ๊ฐ„์œผ๋กœ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๊ฒƒ์„ ๊ตฌํ˜„ํ•ด ๋ด…์‹œ๋‹ค.

์‹ค์Šต ์ฝ”๋“œ

index.html

<!DOCTYPE html>
<html>
    <body>
        <span>Total Click: 0</span>
        <button id = "btn">๋ฒ„ํŠผ</button>
    </body>
    <script>
        let cnt = 0;
        const button = document.getElementById("btn");
        const span = document.querySelector("span");
        function clickCounter(){
            cnt+=1;
            span.innerText = `Total Click: ${cnt}`;
            console.log(cnt);
        }
        button.addEventListener("click",  clickCounter);
    </script>
</html>

์‹คํ–‰๊ฒฐ๊ณผ

๋ฒ„ํŠผ ํด๋ฆญ ์ „์ž…๋‹ˆ๋‹ค.

์•„๋ž˜์™€ ๊ฐ™์ด ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ์›น ํŽ˜์ด์ง€ ๋ฐ ์ฝ˜์†”์— ํด๋ฆญ ํšŸ์ˆ˜๊ฐ€ ์ถœ๋ ฅ๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


JavaScript์™€ HTML๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๊ฐ„๋‹จํ•œ Interactive Web ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•ด ๋ดค์Šต๋‹ˆ๋‹ค.

ํฌ์ŠคํŒ… ๋‚ด์šฉ์— ์˜ค๋ฅ˜๋‚˜ ์งˆ๋ฌธ์ด ์žˆ๋‹ค๋ฉด ๋Œ“๊ธ€ ๋‚จ๊ฒจ์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌ๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค.

๊ณ ๋ง™์Šต๋‹ˆ๋‹ค :)

 

728x90
๋ฐ˜์‘ํ˜•