라디오 버튼이나 체크박스를 클릭할때
해당 버튼을 클릭하지 않고 버튼옆에 텍스트를 클릭해도
그 버튼이 선택되도록 하는 태그입니다.
스크립트를 쓰지 않고 태그로 간단하게 사용이 가능합니다.

일반 사용예 : <input type="checkbox" id="chk1">체크박스1
label 사용예 : <label for="chk2"><input type="checkbox" id="chk2" name="chk2">체크박스2</label>

해당 input 태그에 사용할 id 를 정해주고
위 처럼 라벨 태그의 for="해당id" 해주시면 됩니다.

'JQuery' 카테고리의 다른 글

체크박스 하나만 선택되도록 하는 함수  (0) 2020.02.11

function onlyOneCheck(groupName){
     var chk = $('[data-group="'+groupName+'"]').find('input[type="checkbox"]');
     chk.click(function(){
         if($(this).is(':checked')){
            chk.not(this).prop('checked',false); // .not() : 선택한 요소 제외한 나머지 요소
        }
    })
}

//체크박스 한개만 선택 되도록 onload시 설정 

$(document).ready(function(){
    onlyOneCheck("checkFail");
});

<th> 내/외부요인 </th>

<td data-group="checkFail">

    <div clas ="check floatLeft">

    <input id="in"  class="checkbox-custom" name="anctInoutFactorCode" value="I" type="checkbox" /> 내

    <input id="out"  class="checkbox-custom" name="anctInoutFactorCode" value="O" type="checkbox" /> 외

   </div>

</td> 

 

 

 

+ Recent posts