개발/자바스크립트 및 프론트
자바스크립트 ) 부트스트랩에서 Modal 닫기 버튼 무력화 하기
kakk789
2023. 6. 21. 15:20
HTML
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" id="modalCloseButton"></button>
자바스크립트
document.addEventListener("DOMContentLoaded", function () {
var modalOptions = {
backdrop: 'static', // background 클릭 시 모달이 꺼지지 않도록 설정
keyboard: false // ESC 키 누를 때 모달이 꺼지지 않도록 설정
};
var modalElement = document.getElementById("modal-bldsel");
var modal = new bootstrap.Modal(modalElement, modalOptions);
var closeButton = document.getElementById("modalCloseButton");
closeButton.removeAttribute("data-bs-dismiss");
closeButton.removeAttribute("aria-label");
closeButton.addEventListener("click", function () {
if (enteNmElement.textContent.trim() === '') {
alert("닫기 불가능입니다."); // 메시지 띄우기
}else{
modal.hide();
}
});
)};
반응형