jQuery的cookie插件實(shí)現(xiàn)保存用戶登陸信息
<!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(){
//如果選中了保存用戶名選項(xiàng)
if($("#chkSave").is(":checked")){
//設(shè)置Cookie值
$.cookie("name",$("#username").val(),{
expires:7,//設(shè)置保存期限
path:"/"http://設(shè)置保存的路徑
});
}else{
//銷毀對(duì)象
$.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常用功能實(shí)戰(zhàn)
本文是實(shí)戰(zhàn)篇. 使用jQueryUI完成制作網(wǎng)站的大部分常用功能.2011-02-02jQuery :nth-child前有無空格的區(qū)別分析
:nth-child(index)子元素過濾選擇器的描述是:選取每個(gè)父元素下的弟index個(gè)子元素,index從1開始。2011-07-07jquery實(shí)現(xiàn)彈出窗口效果的實(shí)例代碼
這篇文章主要介紹了jquery實(shí)現(xiàn)彈出窗口效果的實(shí)例代碼。需要的朋友可以過來參考下,希望對(duì)大家有所幫助2013-11-11jquery改變disabled的boolean狀態(tài)的三種方法
改變disabled的boolean狀態(tài),下面為大家介紹三種比較不錯(cuò)的方法,大家可以參考下2013-12-12jQuery實(shí)現(xiàn)動(dòng)態(tài)加載瀑布流
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)動(dòng)態(tài)加載瀑布流,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-09-09jquery實(shí)現(xiàn)可自動(dòng)收縮的TAB網(wǎng)頁選項(xiàng)卡代碼
這篇文章主要介紹了jquery實(shí)現(xiàn)可自動(dòng)收縮的TAB網(wǎng)頁選項(xiàng)卡代碼,涉及jquery鼠標(biāo)事件及頁面元素樣式變換的實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09jQuery EasyUI 中文API Button使用實(shí)例
jQuery EasyUI 中文API Button使用小結(jié),需要的朋友可以參考下。2010-04-04jQuery+datatables插件實(shí)現(xiàn)ajax加載數(shù)據(jù)與增刪改查功能示例
這篇文章主要介紹了jQuery+datatables插件實(shí)現(xiàn)ajax加載數(shù)據(jù)與增刪改查功能,涉及jQuery結(jié)合datatables插件針對(duì)頁面表格實(shí)現(xiàn)數(shù)據(jù)加載及增刪改查等相關(guān)操作技巧,需要的朋友可以參考下2018-04-04