Notice
Recent Posts
Recent Comments
Links
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Today
In Total
관리 메뉴

A Joyful AI Research Journey🌳😊

230329 jQuery 전체 약관, 선택 약관 눌렀을 때 전체, 특정 체크 박스 클릭 되게 만들기 본문

💻Bootcamp Self-Study Revision✨/JavaScript, jQuery, Ajax

230329 jQuery 전체 약관, 선택 약관 눌렀을 때 전체, 특정 체크 박스 클릭 되게 만들기

yjyuwisely 2023. 3. 30. 00:16

230329

기본틀은 아래와 같고
input에 name, type, id 등 다양한 걸 넣을 수 있다.

검색하면 보통 전체 약관 동의만 떠서 그런데
선택 약관 코드도 넣었다.

<script type="text/javascript" src="https://code.jquery.com/jquery-3.6.3.min.js"></script><!-- jQuery 불러온다 -->

코드) 전체 약관, 선택 약관, 이메일, SMS 각 눌렀을 때 체크박스 체크되게 만들기

//전체 약관 동의
function checkAll() {
    if ($("#TermsOfService").is(':checked')) {
        $("input[name=sub_TermsOfServiceRequired]").prop("checked", true);
    } else {
        $("input[type=checkbox]").prop("checked", false);
    }
}

//선택 약관 동의
function checkOptional() {
    if ($("#TermsOfServiceOptional").is(':checked')) {
        $("input[name=sub_TermsOfServiceOptional]").prop("checked", true);
    } else {
        $("input[type=checkbox]").prop("checked", false);
    }
}

//이메일 수신 체크시 '(선택) 마케팅 정보 수신 동의' 동의 
function checkOptionalEmail() {
    if ($("#sub_TermsOfService6").is(':checked')) {
        $("input[id=sub_TermsOfService5]").prop("checked", true);
    } else {
        $("input[type=checkbox]").prop("checked", false);
    }
}

//SNS 수신 체크시 '(선택) 마케팅 정보 수신 동의' 동의 
function checkOptionalSms() {
    if ($("#sub_TermsOfService7").is(':checked')) {
        $("input[id=sub_TermsOfService5]").prop("checked", true);
    } else {
        $("input[type=checkbox]").prop("checked", false);
    }
}

결과) 진행중인 개인 프로젝트의 이미지를 가져왔다.

필수 약관 전체 동의 눌렀을 때
선택 약관 전체 동의 눌렀을 때
이메일 눌렀을 때
SMS 눌렀을 때


기타 참고 가능

https://openlife.tistory.com/381


728x90
반응형
Comments