通過jquery.cookie.js實現記住使用者名稱和密碼的功能
阿新 • • 發佈:2019-01-11
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script src="jquery1-11.js"></script> <script src="jquery.cookie.js"></script> <script> $(document).ready(function(){ if($.cookie("userName")){ alert('填充cookie'); $('.userName').val($.cookie("userName")); $('.pwd').val($.cookie("pwd")); } $('button').click(function(){ var userName=$('.userName').val(); var pwd=$('.pwd').val(); $.cookie("userName",userName,{expires:7}); // 儲存七天 $.cookie('pwd',pwd,{expires:7}); alert('成功勝出cookie,下次進網頁自動填充'); }) }) </script> </head> <body> <input type="text" class="userName"/><br/><br/> <input type="password" class="pwd"/><br/><br/> <button >登入</button> </body> </html>