๐Ÿ“Œ ๊ฐ„๋‹จํ•œ ์•Œ๋Ÿฟ์ฐฝ ๋งŒ๋“ค๊ธฐ

jjyu_myยท2025๋…„ 2์›” 3์ผ

JAVASCRIPT

๋ชฉ๋ก ๋ณด๊ธฐ
6/15
post-thumbnail

๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป ์˜ˆ์ „์— ๋Š์–ด๋†“๊ณ  ์‹œ๊ฐ„์ด ์—†์–ด์„œ ๋ฏธ๋ค„๋‘” ๊ฐ•์˜๋ฅผ ๋ณต์Šต ์ฐจ์›์—์„œ ๋น ๋ฅด๊ฒŒ ๋“ฃ๋Š” ์ค‘์ด๋‹ค~!
์•„์ฃผ์•„์ฃผ ์‰ฌ์šด ์•Œ๋Ÿฟ์ฐฝ ๋งŒ๋“ค๊ธฐ!!!
์‰ฝ์ง€๋งŒ ํŒŒ๋ผ๋ฏธํ„ฐ ์ดํ•ด๋Š” ์ค‘์š”ํ•œ ๊ฐœ๋…์ด๋‹ค!! ์ด๊ฑฐ ์ดํ•ด ๋ชปํ•˜๋ฉด JS ์–ด๋ ค์›€! ๐Ÿ˜†


๐Ÿ“Œ ๊ฐ„๋‹จํ•œ ์•Œ๋Ÿฟ ์ฐฝ ๋งŒ๋“ค๊ธฐ

  • ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ์•Œ๋Ÿฟ ์ฐฝ์ด ๋ณด์ด๊ณ , ๋‹ซ๊ธฐ ๋ฒ„ํŠผ(โŽ)์„ ๋ˆ„๋ฅด๋ฉด ๋‹ซํžˆ๊ธฐ

๐Ÿ’Ž HTML

<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="./css/02_AlertBox.css">
</head>
<body>
<!-- ์•Œ๋Ÿฟ๋ฐ•์Šค -->
<div class="alert-box" id="alert">Hello~Javascript Alert box!!
  <button class="closebutton" onclick="alertButton('none')">โŽ</button>
</div>

<!-- ์•Œ๋Ÿฟ ์—ด๊ธฐ ๋ฒ„ํŠผ -->
<button class="clickbutton" onclick="alertButton('block')">Click</button>

<script>
  // displayState๋ฅผ ํŒŒ๋ผ๋ฏธํ„ฐ(์ธ์ž)๋กœ ๋ฐ›์•„์„œ alertBox๋ฅผ ๋ณด์—ฌ์ฃผ๊ฑฐ๋‚˜ ์ˆจ๊ฒจ์ฃผ๋Š” ํ•จ์ˆ˜
  function alertButton(displayState){ 
    document.getElementById('alert').style.display=displayState;
  }
</script>

</body>
</html>

๐ŸŽจ CSS

.alert-box {
  background-color: rgb(255, 255, 137);
  padding: 20px;
  color: rgb(49, 152, 35);
  border-radius: 5px;
  display: none;
  font-weight: bold;
  margin-bottom: 5px;
}

.clickbutton{
  cursor: pointer;
  background: rgb(172, 237, 163);
  border: none;
  padding: 5px;
  font-size: 20px;
  border-radius: 10px;
}

.closebutton{
  float: right;
  font-size: 20px;
  background: none;
  border: none;
  cursor: pointer;
}

๐Ÿ”น ์ •๋ฆฌ

  • Click ๋ฒ„ํŠผ โ†’ ์•Œ๋Ÿฟ ์ฐฝ ๋ณด์ด๊ธฐ
  • โŽ ๋ฒ„ํŠผ โ†’ ์•Œ๋Ÿฟ ์ฐฝ ๋‹ซ๊ธฐ
  • alertButton(displayState) ํ•จ์ˆ˜๋ฅผ ํ™œ์šฉํ•ด display ์†์„ฑ์„ ๋ณ€๊ฒฝ
  • css ๋Š” ์ทจํ–ฅ๊ป ์ฝ”๋“œ์งœ๊ธฐ~~~๐Ÿ˜Ž

โœ… ๊ฒฐ๊ณผ

profile

0๊ฐœ์˜ ๋Œ“๊ธ€