728x90
반응형
✅ 방법 1: 플래그 변수 사용
let isModalOpen = false;
$("#createReport").on('click', () => {
if (isModalOpen) return;
isModalOpen = true;
const modal = new TaskReportCreateModal();
modal.popup();
$(modal).one('save-complete', () => {
isModalOpen = false;
location.reload();
});
// 모달이 닫힐 때 플래그 초기화 (필요한 경우)
$(modal).one('hidden', () => {
isModalOpen = false;
});
});
✅ 방법 2: DOM 요소 검사로 중복 방지
$("#createReport").on('click', () => {
if ($('.task-report-modal').length > 0) return;
const modal = new TaskReportCreateModal();
modal.popup();
$(modal).one('save-complete', () => {
location.reload();
});
});
근데 , 나는 모달 html을 공통으로 여러군데에서 쓰고 있고, id값도 매번 동적으로 생성해서 다르기 때문에 체크해서 중복을 거를 수 없어서 방법 1로 하였다.
근데 닫기나 취소버튼을 누를 때 hidden 이벤트로 적용이 안되어서 클릭 이벤트로 추가하였다.
$(`#${this.modal.id} .close`).on('click', () => {
this.close();
});
728x90
반응형
'Front > JS & jQuery' 카테고리의 다른 글
[js] 문자열 추출 split/ slice (0) | 2025.05.14 |
---|---|
[js] dropzone chunking, forceChunking (0) | 2025.05.13 |
[js] trythy / falsy란? (0) | 2025.04.10 |
[js] ! / !! (느낌표/ 느낌표느낌표) (0) | 2025.04.09 |
[js] !! (0) | 2025.04.08 |