jQuery的cookie插件實(shí)現(xiàn)保存用戶登陸信息
更新時(shí)間:2014年04月15日 16:16:04 作者:
保存用戶登陸信息的方法有很多,本文為大家介紹的這個(gè)方法是通過cookie插件來實(shí)現(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(){
//如果選中了保存用戶名選項(xiàng)
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)文章
javaScript和jQuery自動(dòng)加載簡單代碼實(shí)現(xiàn)方法
給大家介紹一下利用javaScript和jQuery實(shí)現(xiàn)自動(dòng)加載最簡單的代碼寫法。2017-11-11
Jquery如何使用animation動(dòng)畫效果改變背景色的代碼
這篇文章主要介紹了Jquery如何使用animation動(dòng)畫效果改變背景色,需要的朋友可以參考下2020-07-07
利用jQuery實(shí)現(xiàn)WordPress中@的ID懸浮顯示評論內(nèi)容
這篇文章主要介紹了使用JavaScript實(shí)現(xiàn)WordPress中ID懸浮顯示評論的功能,就是在樓中樓式的評論中顯示被評論的主體內(nèi)容,需要的朋友可以參考下2015-12-12
使用jquery的cookie實(shí)現(xiàn)登錄頁記住用戶名和密碼的方法
今天小編就為大家分享一篇關(guān)于使用jquery的cookie實(shí)現(xiàn)登錄頁記住用戶名和密碼的方法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-03-03
詳細(xì)介紹jQuery.outerWidth() 函數(shù)具體用法
這篇文章通過jQuery示例代碼演示outerWidth()函數(shù)的具體用法,介紹的非常詳細(xì),有需要的朋友可以借鑒2015-07-07
jQuery+CSS3實(shí)現(xiàn)樹葉飄落特效
本文給大家分享的是一段使用jQuery+CSS3實(shí)現(xiàn)樹葉飄落特效的代碼,效果非常不錯(cuò),分享給大家,希望大家能夠喜歡2015-02-02
JQuery 構(gòu)建客戶/服務(wù)分離的鏈接模型中Table中的排序分析
從上篇文章,我們實(shí)現(xiàn)了Table分頁代碼的高效性,咱們繼續(xù)沿著這個(gè)思路,探討Table表格數(shù)據(jù)中另外一個(gè)很常見的排序問題。說到排序,我記得在asp.net中 GridView中提供了這樣的方便,只需在展示字段上加上 Sorting 這樣的屬性,基本就完成了,剩下就是服務(wù)端cs代碼的寫法了。2010-01-01

