jQuery的cookie插件实现保存用户登陆信息 - Web前端
作者:98wpeu发布时间:2026-06-13分类:网页前端技术浏览:3
导读:复制代码代码如下:<!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禁止输入数字以外的字符的示例(纯数字验证码) - Web前端
- jquery实现更改表格行顺序示例 - Web前端
- jQuery toggleClass应用实例(附效果图) - Web前端
- jquery图片播放浏览插件prettyPhoto使用详解 - Web前端
- 为jquery的ajaxfileupload增加附加参数的方法 - Web前端
- jquery禁用右键单击功能屏蔽F5刷新 - Web前端
- jquery自动填充勾选框即把勾选框打上true - Web前端
- 用JQuery实现全选与取消的两种简单方法 - Web前端
- jquery图片轮播插件仿支付宝2013版全屏图片幻灯片 - Web前端
- jquery选择器之属性过滤选择器详解 - 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属性


