Bootstrap 모달

OROSY·2021년 4월 18일
0

Bootstrap

목록 보기
5/9
post-thumbnail

Bootstrap 모달

Boostrap을 통해 모달 창을 손쉽게 구현할 수 있습니다. 이번에는 모달 형식을 통해 저번 시간에 배운 Forms와 함께 로그인 창을 만들어보도록 합시다. 덧붙여, 모달 창이 뜨면, JavaScript 문법을 통해 아이디 부분에 포커스가 될 수 있도록 구현해볼 수 있습니다.

출처: Bootstrap Modal

1.1 활용 예제

HTML

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <!-- Login -->
        <form>
          <div class="mb-3">
            <label for="exampleInputEmail1" class="form-label">Email address</label>
            <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
            <div id="emailHelp" class="form-text">We'll never share your email with anyone else.</div>
          </div>
          <div class="mb-3">
            <label for="exampleInputPassword1" class="form-label">Password</label>
            <input type="password" class="form-control" id="exampleInputPassword1">
          </div>
          <div class="mb-3 form-check">
            <input type="checkbox" class="form-check-input" id="exampleCheck1">
            <label class="form-check-label" for="exampleCheck1">Check me out</label>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Submit</button>
      </div>
    </div>
  </div>
</div>

JavaScript

const emailInputEl = document.querySelector('#exampleInputEmail1')
const modalEl = document.querySelector('#exampleModal')

modalEl.addEventListener('shown.bs.modal', function () {
  emailInputEl.focus()
})

1.2 화면 출력

profile
Life is a matter of a direction not a speed.

0개의 댓글