728x90
반응형
로그인 버튼을 눌렀을 시 로그인() 함수 안에 넣어놨었는데..
아이디 저장이 되지 않았다.
var userInputEmail = $.cookie('email', $("#email_real").val(), { expires : 365 });
var userInputCheckBox = $.cookie('idSave', $("#idSave").val());
console.log('userInputEmail >>> ', userInputEmail)
console.log('userInputCheckBox >>> ', userInputCheckBox)
$('input[name="email_real"]').val(userInputEmail);
$('input[name="idSave"]').val(userInputCheckBox);
if($('input[name=email_real]').val() != "") { //전에 ID를 저장해서 처음 로그인페이지 로딩,
console.log('체크박스 상태'); //아이디 저장이 체크가 되어 있을 시,
$('#idSave').attr('checked', true); //체크박스의 체크상태로 둔다.
}
$('#idSave').change(function() { //해당 체크박스의 체크여부를 감지.
console.log('체크박스 감지')
if($('#idSave').is(':checked')) { //체크박스에 체크를 했을 시
console.log('체크박스 ON')
var userInputEmail = $('input[name="email_real"]').val();
var userInputCheckBox = $('input[name="idSave"]').val();
$.cookie('email', $("#email_real").val(), { expires : 365 }); //쿠키 삭제를 하루로 지정해놓음.
$.cookie('idSave', $("#idSave").val(), { expires : 365 });
} else { //체크박스에 체크를 해제 시
console.log('체크박스 OFF')
$.removeCookie('email', $("#email_real").val(), { expires : 365 });
$.removeCookie('idSave', $("#idSave").val(), { expires : 365 });
}
});
그래서 아래와 같이 바꿨다.
$(document).ready(function() {
if($('input[name="email_real"]').val() != "") {
console.log('체크박스 여부');
$('#idSave').attr('checked', true);
}
$('#idSave').change(function() { //해당 체크박스의 체크여부를 감지.
console.log('체크박스 감지');
if($('#idSave').is(':checked')) { //체크박스에 체크를 했을 시
console.log('체크박스 ON');
$.cookie('email', $("#email_real").val(), { expires : 365 }); //쿠키 삭제를 365일로 지정해놓음.
$.cookie('idSave', $("#idSave").val(), { expires : 365 });
} else { //체크박스에 체크를 해제 시
console.log('체크박스 OFF');
$.removeCookie('email', $("#email_real").val(), { expires : 365 });
$.removeCookie('idSave', $("#idSave").val(), { expires : 365 });
}
});
callCookie();
});
쿠키 저장 값 참고는 아래 블로그를 참고했습니다.
반응형
'멍청멍청기록 > 프로젝트 일지' 카테고리의 다른 글
프로젝트] Map.put 을 사용할 때 주의해야할 점. (0) | 2020.08.04 |
---|---|
프로젝트] intelliJ common.properties 사용하기. (0) | 2020.08.04 |
프로젝트] java8 이하 for문과 향상된 for문 (0) | 2020.07.22 |
프로젝트] Mybatis UPDATE Multi ForEach 하기 (0) | 2020.07.13 |
프로젝트] ajax 로 데이터 보낼 시 feat. ajax 숫자 데이터 변환시 오류가 발생했습니다. 해결방법. (0) | 2020.07.13 |