아이디(ID) 저장 체크 박스 > 소스코드

본문 바로가기
사이트 내 전체검색


회원로그인

소스코드

jQuery | 아이디(ID) 저장 체크 박스

페이지 정보

작성자 100K5 작성일14-10-08 21:27 조회61,823회 댓글0건

본문

<script type="text/javascript" src="/_js/custom/cookies.js"></script>

<!-- 위의 한줄 소스를 아래와 같이 서술 해도 된다. -->

<script type="text/javascript">
 function setCookie(name,value,expiredays) { 
 var today = new Date();
 today.setDate(today.getDate()+expiredays);
 document.cookie = name + "=" + escape(value) + "; path=/; expires=" + today.toGMTString() + ";";
}

function getCookie( name ) {
   var nameOfCookie = name + "=";
   var x = 0;
   while ( x <= document.cookie.length )
   {
     var y = (x+nameOfCookie.length);
     if ( document.cookie.substring( x, y ) == nameOfCookie ) {
       if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
         endOfCookie = document.cookie.length;
       return unescape( document.cookie.substring( y, endOfCookie ) );
     }
     x = document.cookie.indexOf( " ", x ) + 1;
     if ( x == 0 )
       break;
   }
   return "";
}
</script>

<!-- 로그인 페이지 -->

<script type="text/javascript">
function loginGo(){ 
 if ($("#user_id_save").attr("checked")) { // 아이디 저장을 체크 하였을때    
  setCookie("u_id", $("#u_id").val(), 7); //쿠키이름을 id로 아이디입력필드값을 7일동안 저장
 } else { // 아이디 저장을 체크 하지 않았을때  
  setCookie("u_id", $("#u_id").val(), 0); //날짜를 0으로 저장하여 쿠키삭제
 }

 $("#logFrm").submit();
 
}

$(function(){

  if (getCookie("u_id")) { // getCookie함수로 id라는 이름의 쿠키를 불러와서 있을경우
          
  $("#u_id").val(getCookie("u_id")); //input 이름이 id인곳에 getCookie("user_id")값을 넣어줌

   $(":checkbox[id=user_id_save]").attr("checked", true); // 체크는 체크됨으로

 }

$("#u_id").focus();
 
 $("input").keypress(function(event){
  if (event.keyCode == 13)
  {
   loginGo();
  }
 }).filter("[name=u_id]").focus();

});
</script>

<form name="logFrm" id="logFrm" method="post" action="/log_in_ok.asp">
 <div class="login_box">
 <fieldset>
  <legend>로그인</legend>
  <div class="list">
   <ul>
    <li><label for="u_id" class="h">아이디</label><input type="text" id="u_id" name="u_id" tabindex="1" class="inp_txt" value=""></li>
    <li><label for="u_pwd" class="h">비밀번호</label><input type="password" id="u_pwd" name="u_pwd" tabindex="2" class="inp_txt"></li>
   </ul>
   <a onclick="loginGo();" style="cursor:pointer;" onfocus="this.blur();" class="btn"><img src="/images/btn/btn_login.jpg" alt="로그인"></a>
   <p class="id_save"><input type="checkbox" name="user_id_save" id="user_id_save" value="" /><label for="user_id_save"> 아이디 저장</label></p>
  </div>
 </fieldset>
</div> 

</form>


댓글목록

등록된 댓글이 없습니다.


사이트소개 개인정보취급방침 서비스이용약관 Copyright © kkujunhee.net All rights reserved.
상단으로

개인정보관리책임자 : 관리자

모바일 버전으로 보기