본문 바로가기
Developer/Javascript & jQuery

[Jquery] 모든 radio값 초기화

by 순수한소년 2024. 3. 10.
728x90
반응형

 

@

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
<script type="text/javascript">
//<![CDATA[
    $(document).ready(function(e){
 
        $(document)
            .on('click','#click_resetSearchKey'function(e) {
                e.preventDefault();
                $('#searchName').val("");
                $('#searchMemberId').val("");
 
                var radio_name = [];
                var radio = $("input[type=radio]");      //라디오 정보를 가져옵니다.
                $.each(radio, function (key, value) {    // input radio의 name 값을 가져옵니다.
                    radio_name.push($(value).attr('name'));
                });
                console.log("radio_name:"+radio_name);    //(9) ["school", "school", "school", "school", "sx", "sx", "grade", "grade", "grade"] log값
                radio_name = $.unique(radio_name.sort()).sort(); //중복요소 이름을 제거
                console.log(radio_name);                //(3) ["grade", "school", "sx"] log 값
                for (var i = 0; i < radio_name.length; i++) {
                    $('input[name="' + radio_name[i] + '"]').removeAttr('checked');    //체크되어있는 항목 모두 해제
                    $('input[name="' + radio_name[i] + '"]')[0].checked = true;        //name에서 첫번쨰 요소만 선택
                }
            })                
    });
//]]>
</script>
cs

@

 

출처

https://minaminaworld.tistory.com/45

 

jquery 모든 radio button 모두 초기화 하기

jquery 모든 radio button 모두 초기화 하기 jQuery로 모든 라디오 버튼을 초기화는 방법을 알아보겠습니다. 1번째, 학교로 구성된 radio button 초기화 하기2번째, 학교로 구성된 radio button 초기화 하기 3번

minaminaworld.tistory.com

 

반응형