网站cookie.js
2016-01-19 09:34
519 查看
cookie.js
放置cookie
取cookie
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
d 4000 ate.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
document.cookie = [name, '=', encodeURIComponent(value), expires].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};
放置cookie
//有cookie
$.cookie('userid', userid, {expires : 7});
$.cookie('password', password, {expires : 7});
$.cookie('save', "yes", {expires : 7});
//无cookie
$.cookie('username', null, {expires : 7});
$.cookie('password', null, {expires : 7});
$.cookie('save', "no", {expires : 7});
取cookie
function checkCookie(){阅读更多
var save = $.cookie('save');
if(save=="yes"){
var userid = $.cookie('userid');
var password = $.cookie('password');
$("#useId").val(userid);
$("#pwd").val(password);
}
}
相关文章推荐
- js对cookie的操作,包括清除网站所有cookie
- jQuery.cookie.js中cookie设置遇到的问题
- js cookie操作
- jquery.cookie.js 使用小结
- 不错的介绍JS中Cookie的文章本篇文章来源于:开发学院 http://edu.codepub.com 原文链接:http://edu.codepub.com/2009/0528/4789.php
- Node.js的40+个资源网站专为Node.js开发者
- Asp.net网站中 js通过input type="file" 上传文件
- python利用cookie登录网站进行访问
- node.js+express+ejs+MongoDB模板修改写《node.js开发指南》中的博客网站实例
- 动态生成JS 实现 .NET 网站广告管理
- js中cookie的使用
- JS设置和读取Cookie的函数
- Node.js开发入门—使用cookie保持登录
- js中实现cookie的增删改查(document.cookie的使用详情)
- js中如何往cookie中放值和取值
- js将网站 加入收藏夹与设为首页方法实现
- Cookie在网站中的两大使用方法[cookie使用]
- js清除cookie
- JS中cookie的使用详解
- 用js正确判断用户名cookie是否存在的方法