jquery.cookie.js $.cookie()是怎么使用
置的cookie,必须设置cookie的路径。cookie的路径用于设置能够读取 cookie的顶级目录。将这
个路径设置为网站的根目录,可以让所有网页都能互相读取 cookie (一般不要这样设置,防止出现冲突) 。
<form action="xxx/user/signIn" method="post" >
<input type="text" id="username" name="username" placeholder="请输入用户名" />
<input type="password" id="password" name="password" placeholder="请输入密码" />
<input type="checkbox" id="remember"> 记住用户名和密码
<button type="submit" class="btn btn-success" id="btn_login">登 录</button>
<button type="reset" class="btn btn-default">重 置</button>
</form> $(document).ready(function(){
//页面初始化时,如果是记住密码了,给输入框赋值。
if($.cookie("remember") == "true"){
$("#remember").prop("checked", true);
$("#username").val($.cookie("username"));
$("#password").val($.cookie("password"));
} //点击确定按钮,将记录状态信息存在cookie,同时submit;
$("#btn_login").on("click",function(){
remember();
return true;
}); //记录用户名密码。以及是否要记住。保存在cookie;
function remember(){
var checked = $("#remember").prop("checked");
if(checked == "checked" || checked) {
var username = $("#username").val();
var password = $("#password").val();
$.cookie("remember", "true", {expires: 30});
$.cookie("username", username, {expires: 30});
$.cookie("password", password, {expires: 30});
}else{
$.cookie("remember", "false", {expires: -1});
$.cookie("username", "", {expires: -1});
$.cookie("password", "", {expires: -1});
}
} //监听记住选择框是否选中,如果未选中,cookie中则不记录。
$("#remember").on("change", function(){
var checked = $("#remember").prop("checked");
if(checked == "checked" || checked) { }else{
$.cookie("remember", "false", {expires: -1});
$.cookie("username", "", {expires: -1});
$.cookie("password", "", {expires: -1});
}
});
});
jquery.cookie.js $.cookie()是怎么使用的更多相关文章
- 管理Cookie的插件——jquery.cookie.js
下载地址:http://plugins.jquery.com/cookie/ jquery.cookie中的操作: 一.创建cookie: 1.创建一个会话cookie: $.cookie('cook ...
- jquery.cookie.js 的使用
jquery.cookie.js 对cookie的操作 $.cookie('the_cookie'); //读取Cookie值 $.cookie('the_cookie', 'the_value'); ...
- 分享jquery.cookie.js
代码如下: /*! * jQuery Cookie Plugin v1.4.1 * https://github.com/carhartl/jquery-cookie * * Copyright 20 ...
- 【jq】插件—缓存jquery.cookie.js
jquery.cookie.js插件 轻量级cookie管理 1°下载地址:http://plugins.jquery.com/cookie/ 2°引入方式:(基于jquery) <scri ...
- JavaScript-Tool:jquery.cookie.js
ylbtech-JavaScript-Tool:jquery.cookie.js 1.返回顶部 1.jquery.cookie.js /*! * jQuery Cookie Plugin v1.4.0 ...
- Juery插件-- jquery.cookie.js
1.引入jquery <script src="scripts/jquery-1.8.8.js" type="text/javascript">&l ...
- jquery中的cookie
关于cookie,一直是个很敏感的问题,以前对于cookie的处理,都是用原生的方式处理,创建函数对cookie进行处理,创建,设置以及删除.. function setCookie(key,valu ...
- jquery中的cookie操作
使用前在页面中引入下面的代码 /*! * jQuery Cookie Plugin v1.4.1 * https://github.com/carhartl/jquery-cookie * * Cop ...
- jquery和js cookie的使用解析
JavaScript是运行在客户端的脚本,因此一般是不能够设置Session的,因为Session是运行在服务器端的.而cookie是运行在客户端的,所以可以用JS来设置cookie. 在这里分别通过 ...
- jquery库的cookie用法
一个完整设置与读取cookie的页面代码: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...
随机推荐
- vue项目启动
这篇文章主要用于有源码vue项目安装: 1.安装node.js环境(npm包管理器)前面博客有写到如何安装: 2.vue-cli 脚手架构建工具前面博客有写到如何安装: 3.cnpm npm的淘宝镜 ...
- Redis (一) 概念安装
一.阿里云安装Redis 1.安装Redis yum -y install redis 2.启动Redis service redis start 或者(推荐使用) systemctl start ...
- C++ bitset
itset存储二进制数位. bitset就像一个bool类型的数组一样,但是有空间优化——bitset中的一个元素一般只占1 bit,相当于一个char元素所占空间的八分之一. bitset中的每个元 ...
- first head in html 笔记
目录: 1.了解HTML 2.学会简单构建网页 3.学会将单个的网页放在web上,组成网站 5.学会使用图片 6.严格HTML规范 7.HTML->XHTML 8.学会一点CSS样式 9.了解盒 ...
- utf-8和Unicode的区别
链接 utf-8和Unicode到底有什么区别?是存储方式不同?编码方式不同?它们看起来似乎很相似,但是实际上他们并不是同一个层次的概念 要想先讲清楚他们的区别,首先应该讲讲Unicode的来由. 众 ...
- 使用kbmMW#1轻松实现REST
使用kbmMW很容易创建REST服务器. 首先,我们制作服务器应用程序(或服务......取决于您). 在这种情况下,我们将添加一个简单的Form,为我们的kbmMW组件提供GUI和位置. 在Delp ...
- DialogFragment详解
详解一: Android提供alert.prompt.pick-list,单选.多选,progress.time-picker和date-picker对话框,并提供自定义的dialog.在Androi ...
- 《TensorFlow实战》读书笔记(完结)
1 TensorFlow基础 ---1.1TensorFlow概要 TensorFlow使用数据流图进行计算,一次编写,各处运行. ---1.2 TensorFlow编程模型简介 TensorFlow ...
- Ubuntu终端点击确定按钮的方法
Ubuntu终端里出现需要点击 确定 按钮的时候,直接鼠标点击 确定 是不生效的,这个时候需要利用tab键选中这个 确定 按钮,然后回车键就可以了.
- 3.3 shell控制流结构
shell中的控制流包括if then else语句,case语句,for循环,until循环,while循环,break控制,continue控制. 条件测试: 有时判断字符串是否相等或检查文件状态 ...