๋ชฉ์ฐจ
bootstrap modal ๐
์ญ์ ๋ฏธ๋์ ๋ด๊ฐ ๋ณด๊ธฐ ์ํด ๋ถํธ์คํธ๋ฉ์ ์ด์ฉํด์ ๋ชจ๋ฌ์ฐฝ์ ๋์ฐ๋ ๋ฐฉ๋ฒ์ ๊ธฐ๋กํ๋ค.
html ์ฝ๋์ js๋ก modal์ ๋์ฐ๋ ๋ฐฉ๋ฒ์ด ์กด์ฌํ๋๋ฐ ์ฌ๊ธฐ์๋ ๊ฐ๋จํ๊ฒ html๋ง์ผ๋ก ๋์ด๋ค.
js๋ก ํ๋ ๋ฐฉ๋ฒ์ ์๋์ฒ๋ผ ์ฝ๋๋ฅผ ์์ ํ๋ฉด ๋๋ค.
button์ id๊ฐ ์ฃผ๊ณ ํด๋น ๋ฒํผ ํด๋ฆญ ์ $("#๋ชจ๋ฌ์์ด๋").modal("show"); ์ด๋ ๊ฒ ์ด๋ฒคํธ๋ฅผ ์ค๋ค.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<title>modal-test</title>
</head>
<body>
<button class="btn btn-danger" type="button" id="btn">์์ </button>
<!-- div modal์ฐฝ ์๋ต -->
<script>
$(document).ready(function() {
$("#btn").on("click", function(){
$("#userModal").modal("show");
});
});
</script>
</body>
</html>
ํ ์คํธ ํ๊ฒฝ: ๋ถํธ์คํธ๋ฉ 5.2.3๋ฒ์
์์ ๋ฒํผ์ ๋๋ฅด๋ฉด id๊ฐ "userModal"์ธ ๋ชจ๋ฌ์ฐฝ์ ๋์ฐ๋ ์์ ์ด๋ค.
bootstrap.min.css, bootstrap.bundle.min.css 2๊ฐ์ ํ์ผ์ด ํ์ํ๋ ์ง์ ๋ค์ด๋ก๋ ํ๊ฑฐ๋ CDN์ผ๋ก ๋ถ๋ฌ์ค๊ฑฐ๋ ํ๋ฉด ๋๋ค.
์๋ ๋งํฌ์์ ๋ค์ด๋ก๋ or CDN
Download
Download Bootstrap to get the compiled CSS and JavaScript, source code, or include it with your favorite package managers like npm, RubyGems, and more.
getbootstrap.com
12 line์ data-bs-toggle="modal" data-bs-target="#userModal" ์์ฑ์ด ์์ผ๋ฉด ๋ชจ๋ฌ์ด ๋จ์ง ์๋๋ค.
์ง๊ด์ ์ผ๋ก ๋ณด๊ธฐ์๋ toggleํ์์ผ๋ก modal์ ๋์ด๋ค๋ ์๋ฆฌ๊ณ ๋์์ #userModal(id="userModal")์ ํ ๊ธํํ๋ค๋ ์๋ฆฌ๋ก ์ดํด๋๋ค.
๋ชจ๋ฌ์ header, body, footer๋ก ์ด๋ฃจ์ด์ ธ ์์ผ๋ ์ ์ ํ ๋ด์ฉ์ ์ ๋ ฅํ๋ฉด ๋๋ค.
34 line์ data-bs-dismiss="modal" ์์ฑ์ ๋ชจ๋ฌ์ฐฝ์ ๋ซ๋ ์ด๋ฒคํธ๋ฅผ ์๋ฏธํ๋ค.
์ด ๊ฐ๋ ์ ์ดํดํ๊ณ ๋ถํธ์คํธ๋ฉ ๊ณต์ ํํ์ด์ง์์ ๊ฐ์ด๋ ๋ณด๊ณ ํ๋ฉด ๋๋ค.
์๋ ์ฝ๋๋ฅผ ์ฒจ๋ถํ๋ค.
See the Pen Untitled by SangYeop Lee (@devLsy) on CodePen.
reference: https://getbootstrap.com/docs/5.2/components/modal/
Modal
Use Bootstrap’s JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
getbootstrap.com

๋๊ธ