jQuery的cookie插件實現(xiàn)保存用戶登陸信息
更新時間:2014年04月15日 16:16:04 作者:
保存用戶登陸信息的方法有很多,本文為大家介紹的這個方法是通過cookie插件來實現(xiàn),需要的朋友可以參考下
復(fù)制代碼 代碼如下:
<!DOCTYPE html>
<html>
<head>
<title>cookies.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
.txt{
width: 150px;
height:20px;
border: 1px blue solid;
border-radius:0.5em;
margin-bottom: 5px;
padding-left: 5px;
}
</style>
<script type="text/javascript" src="../js/jquery-1.10.2.js"></script>
<script type="text/javascript" src="../js/jquery.cookie.js"></script>
<script type="text/javascript">
$(function(){
if($.cookie("name")){
//取值如果存在則賦值
$("#username").val($.cookie("name"));
}
$("#mycookie").submit(function(){
//如果選中了保存用戶名選項
if($("#chkSave").is(":checked")){
//設(shè)置Cookie值
$.cookie("name",$("#username").val(),{
expires:7,//設(shè)置保存期限
path:"/"http://設(shè)置保存的路徑
});
}else{
//銷毀對象
$.cookie("name",null,{
path:"/"
});
}
return false;
});
});
</script>
</head>
<body>
<form action="#" method="get" id="mycookie">
<div>
用戶名:<br>
<input id="username" name="username" type="text" class="txt">
</div>
<div>
密碼:<br>
<input id="password" name="password" type="password" class="txt">
</div>
<div>
<input id="chkSave" type="checkbox">是否保存用戶名
</div>
<div>
<input id="cookBtn" class="btn" type="submit" value="提交">
</div>
</form>
</body>
</html>
相關(guān)文章
從零開始學(xué)習(xí)jQuery (十) jQueryUI常用功能實戰(zhàn)
本文是實戰(zhàn)篇. 使用jQueryUI完成制作網(wǎng)站的大部分常用功能.2011-02-02jQuery :nth-child前有無空格的區(qū)別分析
:nth-child(index)子元素過濾選擇器的描述是:選取每個父元素下的弟index個子元素,index從1開始。2011-07-07jquery改變disabled的boolean狀態(tài)的三種方法
改變disabled的boolean狀態(tài),下面為大家介紹三種比較不錯的方法,大家可以參考下2013-12-12jquery實現(xiàn)可自動收縮的TAB網(wǎng)頁選項卡代碼
這篇文章主要介紹了jquery實現(xiàn)可自動收縮的TAB網(wǎng)頁選項卡代碼,涉及jquery鼠標(biāo)事件及頁面元素樣式變換的實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-09-09jQuery EasyUI 中文API Button使用實例
jQuery EasyUI 中文API Button使用小結(jié),需要的朋友可以參考下。2010-04-04jQuery+datatables插件實現(xiàn)ajax加載數(shù)據(jù)與增刪改查功能示例
這篇文章主要介紹了jQuery+datatables插件實現(xiàn)ajax加載數(shù)據(jù)與增刪改查功能,涉及jQuery結(jié)合datatables插件針對頁面表格實現(xiàn)數(shù)據(jù)加載及增刪改查等相關(guān)操作技巧,需要的朋友可以參考下2018-04-04