function

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="main.css">
</head>
<body>
    <div id="alert" class="alert-box" >
        ์•Œ๋ฆผ์ฐฝ
        <button onclick="document.getElementById('alert').style.display = 'none'">๋‹ซ๊ธฐ</button>
    </div>
    <button onclick="document.getElementById('alert').style.display = 'block'">์•Œ๋ฆผ์ฐฝ์„ ๋ณด์—ฌ์ค˜!</button>
</body>

</html>

์ด๋ ‡๊ฒŒ ๋ผ์ธ์•ˆ์— ๋ชจ๋“  ๋‚ด์šฉ์„ ์ž‘์„ฑํ•˜๋ฉด (js, css) ๋ผ์ธ์ด ๋„ˆ๋ฌด ๊ธธ์–ด์ง€๊ณ  ์ฝ”๋“œ๊ฐ€ ์ง€์ €๋ถ„ํ•ด์ง„๋‹ค.

์ง€์ €๋ถ„ํ•œ ์ฝ”๋“œ = ์ˆ˜์ •, ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ์–ด๋ ต๋‹ค.

<script> 
    function ํ•จ์ˆ˜๋ช…(){
        //ํ•จ์ˆ˜๋‚ด์šฉ ์ž‘์„ฑ
    }
</script>

โœจ์‹ค์Šต. button์— ์žˆ๋Š” javaScript๋ฅผ function์œผ๋กœ ๋ถ„๋ฆฌํ•˜๊ธฐ

๐Ÿซํ•จ์ˆ˜๋ช… ์ž‘๋ช… ๋ฐฉ๋ฒ•(camelCase)

ํ•จ์ˆ˜๋ช…์„ ์ž‘๋ช…ํ• ๋•Œ๋Š” camelCase๋กœ ์ง๊ด€์ ์ด๊ฒŒ ์ž‘์„ฑํ•œ๋‹ค.

๐Ÿ˜ฑ์˜คํƒ€ ์ฃผ์˜!

 function alertPopup(){
     document.getElementById('alret').style.display = 'block'
 }
 
 // alert > alret ์˜คํƒ€ 

์ด๋ ‡๊ฒŒ ์˜คํƒ€๊ฐ€ ๋‚˜๋ฉด ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ด๋„ ๋™์ž‘์„ ์•ˆํ•œ๋‹ค.

๋‹นํ™ฉํ•˜์ง€ ๋ง๊ณ  F12๋ฅผ ๋ˆŒ๋ ค์„œ ๊ฐœ๋ฐœ์ž ๋„๊ตฌ๋ฅผ ์ผœ๋ณด์ž๐Ÿ˜ฅ

์ด๋ ‡๊ฒŒ ์˜ค๋ฅ˜ ๋กœ๊ทธ๋ฅผ ๋ณด๊ณ  ์›์ธ์„ ์ฐพ๊ณ  ์ˆ˜์ •ํ•˜๋Š”๊ฒƒ์„ Debugging(๋””๋ฒ„๊น…) ์ด๋ผ๊ณ  ํ•œ๋‹ค.

ํ•ด๋‹น ์—๋Ÿฌ๋กœ๊ทธ๋ฅผ ๋ณต๋ถ™ํ•ด์„œ ๊ตฌ๊ธ€์— ๊ฒ€์ƒ‰ํ•ด๋ณด์ž.

https://sir.kr/qa/398083 : ์—ฌ๊ธฐ์„œ ๋‹ต๋ณ€์„ ํ™•์ธํ•ด๋ณด์ž

์•ž์œผ๋กœ ๊ฐœ๋ฐœ์„ ํ•˜๋ฉด์„œ ์ˆ˜๋งŽ์€ ์˜ค๋ฅ˜๋“ค์„ ๋งŒ๋‚ ํ…๋ฐ ๋กœ๊ทธ๋งŒ ๋ด๋„ ์•Œ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ๋„ ์žˆ๊ณ  ๋ชจ๋ฅด๊ฒ ์œผ๋ฉด ๊ตฌ๊ธ€์— ๊ฒ€์ƒ‰ํ•ด๋ณด๋ฉด ๋œ๋‹ค.

Last updated