JQuery
체크박스 하나만 선택되도록 하는 함수
흰이슬
2020. 2. 11. 10:04
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>