HTML.Js
라디오버튼 체크해제기능 추가.
landzz
2015. 3. 6. 16:26
html속성특성상
라디오버튼은 한번 클릭하면 다시 해제가 불가한데
누군가가 집요하게 요구하여 만듬
jquery 이용
$("input[type=radio]").each(function(){
var chk = $(this).is(":checked");
var name = $(this).attr('name');
if(chk == true) $("input[name='"+name+"']").data("previous",$(this).val());
});
$("input[type=radio]").click(function(){
var pre = $(this).data("previous");
var chk = $(this).is(":checked");
var name = $(this).attr('name');
if(chk == true && pre == $(this).val()){
$(this).prop('checked',false);
$("input[name='"+name+"']").data("previous",'');
}else{
if(chk == true) $("input[name='"+name+"']").data("previous",$(this).val());
}
});