HTML

<form method="post">
	<input type="text" id="id" class="ip">
	<input type="password" id="pw" class="ip">
	<input type="submit" value="로그인">
	<input type="checkbox" id="save">
</form>	

<!--javascript-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="cookie.js"></script>

JAVASCRIPT

$(document).ready(function(){
    var userID = getCookie("userID");
  
    $("#id").val(userID); 
     
    if($("#id").val() != ""){
        $("#save").attr("checked", true);
    }
  
    $("#save").change(function(){
        if($("#save").is(":checked")){
            var userID = $("#id").val();
            setCookie("userID", userID, 7);
        }else{
            deleteCookie("userID");
        }
    });
  
    $("#id").keyup(function(){
        if($("#save").is(":checked")){
            var userID = $("#id").val();
            setCookie("userID", userID, 7);
        }
    });
});

REFERENCE

  1. 'cookie.js' 다운로드 링크
profile
TJ

0개의 댓글