// S: 페이지에서 이미 name="app_time" input radio가 있어서 클릭 이벤트 발생시
$("input[name='app_time']").click(function(){
	$('input[name="app_time"]').not(target).prop("checked", false);
})
// E: 페이지에서 이미 name="app_time" input radio가 있어서 클릭 이벤트 발생시

// S: 페이지에 클릭 이벤트 설정 name="app_time" input radio를 클릭했을 때
$(document).on("click", "input[name='app_time']", function(){
	$('input[name="app_time"]').not(target).prop("checked", false);
})
// E: 페이지에 클릭 이벤트 설정 name="app_time" input radio를 클릭했을 때

// S:사용자가 선택한 input radio 외에 체크풀기
function selTime (target){
	$('input[name="app_time"]').not(target).prop("checked", false);
}
// E:사용자가 선택한 input radio 외에 체크풀기

보통 한 form 안에서 중복되는 name의 input radio의 경우

중복되지 않도록 체크되지만

 

여러개의 form을 사용하고 input radio의 name이 중복되는 값이 있으면

중복체크가 되지 않는다.

예)

<form id="apply_form_1" name="apply_form" method="post" action="">
	<input type="radio" name="app_time" value= "1">
    	<input type="radio" name="app_time" value= "2">
</form>

<form id="apply_form_2" name="apply_form" method="post" action="">
	<input type="radio" name="app_time" value= "1">
    	<input type="radio" name="app_time" value= "2">
</form>

 

처음부터 form을 중복으로 쓰지 않으면 될 것을......

중복으로 쓰는 경우가 있으니 알아두면 좋을 것 같습니다.

 

출처 : 나의 시행착오와 선임 개발자님이 가르쳐준 내용

+ Recent posts