1. 程式人生 > >Cookie記住密碼

Cookie記住密碼

如果 -c ack 記住密碼 val expires secure eof 刪除

1.導入包jquery.cookie.js

2.存cookie

以用戶名作為cookie的name,密碼作為值存儲。

如果出現存的值一直undefined,則將secure值取false;

 //記住密碼 
                if ($(‘#remenber‘).is(‘:checked‘)) {
                    var COOKIE_NAME = $("#username").val();
                    var COOKIE_VALUE = $("#password").val();
                    $.cookie(COOKIE_NAME, COOKIE_VALUE, { expires: 
1, path: ‘/‘, secure: false }); // alert("" + $.cookie(COOKIE_NAME) + "");//此步驗證存的值 } else { $.cookie(‘COOKIE_NAME‘, ‘‘, { path: ‘/‘ });//刪除cookie }

3.取cookie

獲取當前用戶名,根據用戶名尋找對應的cookie值,如果不是undefined,則cookie值存在,將值放入密碼框中。

 var username = $("#username").val();
                        
var password = $.cookie(username); if (typeof password != ‘undefined‘) { $("#password").val("" + password + ""); }

Cookie記住密碼