jQuery的cookie插件实现保存用户登陆信息 - Web前端
作者:98wpeu发布时间:2026-06-13分类:网页前端技术浏览:32
导读:复制代码代码如下:<!DOCtypehtml><HTML><head><title>cookies.html</tit...
复制代码 代码如下:
<!DOCtypehtml>
<HTML>
<head>
<title>cookies.html</title>
<metahttp-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")){
//设置Cookie值
$.cookie("name",$("#username").val(),{
expires:7,//设置保存期限
path:"/"//设置保存的路径
});
}else{
//销毁对象
$.cookie("name",null,{
path:"/"
});
}
returnfalse;
});
});
</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>
<!DOCtypehtml>
<HTML>
<head>
<title>cookies.html</title>
<metahttp-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")){
//设置Cookie值
$.cookie("name",$("#username").val(),{
expires:7,//设置保存期限
path:"/"//设置保存的路径
});
}else{
//销毁对象
$.cookie("name",null,{
path:"/"
});
}
returnfalse;
});
});
</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>
相关推荐
- 用Jquery重写windows.alert方法实现思路 - Web前端
- jquery.validate.js插件使用经验记录 - Web前端
- 关于query Javascript CSS Selector engine - Web前端
- 基于jQuery中对数组进行操作的方法 - Web前端
- jQuery学习笔记(3)--用jquery(插件)实现多选项卡功能 - Web前端
- jQuery方法简洁实现隔行换色及toggleClass的使用 - Web前端
- js(jQuery)获取时间的方法及常用时间类搜集 - Web前端
- jQuery学习笔记之toArray() - Web前端
- jquery Mobile入门—多页面切换示例学习 - Web前端
- ajax页面无刷新 IE下遭遇Ajax缓存导致数据不更新的问题 - Web前端
- 网页前端技术排行
- 最近发表
-
- WordPress随机显示特色图片插件:Random Post Thumbnails
- KeePass实现Chrome浏览器自动填充密码方法一
- LNMP一键包nginx 301强制跳转到https教程
- KeePass实现Chrome浏览器自动填充密码方法二
- #建站# 免费的VPS管理软件Xshell8/Xftp8中文版下载
- 使用Xshell 8连接VPS教程_电脑登录vps的方法
- WordPress评论界面添加烟花????效果
- 不同浏览器书签同步方案:坚果云+Floccus_详细使用教程
- iOS端KeePassXC客户端APP:Strongbox Password Safe
- 给WordPress评论中的Gravatar头像图片添加ALT属性


