问题: cookie设置好后,谷歌浏览器下-->只有本页面有值,但是在其它浏览器下正常.

$.cookie("userName",$("#loginName").val(),{expires:7});
$.cookie("password",$("#loginPW").val(),{expires:7});

原因是: 木有设置cookie路径...--> 搞定

$.cookie("userName",$("#loginName").val(),{expires:7,path:'/'});
$.cookie("password",$("#loginPW").val(),{expires:7,path:'/'});

使用了jquery.cookie.js: 代码如下-->

/*jslint browser: true */ /*global jQuery: true */

/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
//Downloads By http://www.veryhuo.com
// TODO JsDoc /**
* Create a cookie with the given key and value and other optional parameters.
*
* @example $.cookie('the_cookie', 'the_value');
* @desc Set the value of a cookie.
* @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
* @desc Create a cookie with all available options.
* @example $.cookie('the_cookie', 'the_value');
* @desc Create a session cookie.
* @example $.cookie('the_cookie', null);
* @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
* used when the cookie was set.
*
* @param String key The key of the cookie.
* @param String value The value of the cookie.
* @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
* @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
* If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
* If set to null or omitted, the cookie will be a session cookie and will not be retained
* when the the browser exits.
* @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
* @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
* @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
* require a secure protocol (like HTTPS).
* @type undefined
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/ /**
* Get the value of a cookie with the given key.
*
* @example $.cookie('the_cookie');
* @desc Get the value of a cookie.
*
* @param String key The key of the cookie.
* @return The value of the cookie.
* @type String
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/
jQuery.cookie = function (key, value, options) { // key and at least value given, set cookie...
if (arguments.length > 1 && String(value) !== "[object Object]") {
options = jQuery.extend({}, options); if (value === null || value === undefined) {
options.expires = -1;
} if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
} value = String(value); return (document.cookie = [
encodeURIComponent(key), '=',
options.raw ? value : encodeURIComponent(value),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
} // key and possibly options given, get cookie...
options = value || {};
var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

cookie设置的更多相关文章

  1. 浏览器因cookie设置HttpOnly标志引起的安全问题

    1.简介 如果cookie设置了HttpOnly标志,可以在发生XSS时避免JavaScript读取cookie,这也是HttpOnly被引入的 原因.但这种方式能防住攻击者吗?HttpOnly标志可 ...

  2. SoapUI之cookie设置

    一.测试背景: 1)接口测试需要完成注册-->登录-->充值,使用soapui构建好测试用例.设置断言后,运行结果如下: 2)recharge接口运行失败,继续查看该接口具体发送的请求及返 ...

  3. PHP如何清除COOKIE?PHP无法删除COOKIE?设置COOKIE有效期、COOKIE过期

    cookie和session的区别? http://www.cnblogs.com/phphuaibei/archive/2011/11/15/2250082.html PHP如何清除COOKIE?P ...

  4. ★★★【卡法 常用js库】: js汇合 表单验证 cookie设置 日期格式 电话手机号码 email 整数 小数 金额 检查参数长度

    [卡法 常用js库]: js汇合 表单验证  cookie设置  日期格式  电话手机号码  email  整数  小数  金额   检查参数长度 // +---------------------- ...

  5. iOS 和 H5 页面交互(WKWebview 和 UIWebview cookie 设置)

    iOS 和 H5 页面交互(WKWebview 和 UIWebview cookie 设置) 主要记录关于cookie相关的坑 1. UIWebview 1. UIWebview 相对比较简单 直接通 ...

  6. js中cookie设置、获取与清除

    // 设置cookie setCookie (cname, cpwd, exdays) { var exdate = new Date()// 获取时间 exdate.setTime(exdate.g ...

  7. cookie设置中文时的编码问题

    cookie设置中文时的编码问题:cookie在设置时不允许出现中文.非要设置中文的怎么办,看下面的解决方案: 方式1 def login(request): ret = HttpResponse(' ...

  8. Tornado中的Cookie设置

    Tornado中的cookie分为两种--普通cookie和安全cookie 普通cookie 1.创建cookie 原型 self.set_cookie(name, value, domain=No ...

  9. safari cookie设置中文失败

    最近用H5进行手机端开发,由于是window操作系统,为了方便开发和调试,直接在chrome浏览器上进行测试,然后在android机上进行手机端测试,当功能基本完工后,原来在android上运行正常的 ...

随机推荐

  1. 通过ReconstructMe实现3D扫描

    实物3D建模 目前在3D游戏制作过程中,需要专业人士花几天甚至数星期的时间,借助于Autodesk 3ds Max和Maya等昂贵的软件工具制作3D模型.纹理和动画.游戏制作中经常使用一种方法,即设计 ...

  2. CD冷却效果实现

    在NGUI中实现CD转圈的特效,可以用图片控件中UISprite组件的Fill Amount属性去控制. 在上图中skill表示需要冷却技能的图片:其子控件Label表示右下角的快捷键“Y”:子控件S ...

  3. 使用Emmet加速Web前端开发

    Emmet插件以前被称作为Zen Coding,是一个文本编辑器的插件,它可以帮助您快速编写HTML和CSS代码,从而加速Web前端开发.早在2009年,Sergey Chikuyonok写过一篇文章 ...

  4. Eclipse中Ctrl+Alt+Down和Ctrl+Alt+Up不起作用

    不起作用是因为跟因特尔的快捷键冲突. 1.在桌面上右键,选择“图形属性......” 2.选择“选项和支持” 3.更改快捷键. 注意:单纯禁用英特尔的快捷键可能不起作用.

  5. select, poll, epoll

    select的一 个缺点在于单个进程能够监视的文件描述符的数量存在最大限制,在Linux上一般为1024 http://www.cnblogs.com/bigwangdi/p/3182958.html ...

  6. C#入门经典第六章函数-2-委托

    委托:

  7. javascript 中arguments.callee 调用自身

    一.Arguments该对象代表正在执行的函数和调用他的函数的参数.[function.]arguments[n]参数function :选项.当前正在执行的 Function 对象的名字.n :选项 ...

  8. 货物搬运(move)

    货物搬运(move) 题目描述 天地无情人有情,一方有难八方支援!汶川大地震发生后,灾区最紧缺的是救灾帐篷,全国各地支援的帐篷正紧急向灾区运送.假设围绕纹川县有环行排列的n个救灾帐篷的存储点,每个存储 ...

  9. linux 备份系统

    切换到root用户 切换到根目录 tar cvpzf backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz -- ...

  10. 序列化为XML

    java类序列化成xml 方法[转] 今天看了下JAVA序列化.还是一知半解.怎么也没有弄明白,怎么序列化成XML文件.处入半解状态.在网上找了很多,大部分是理论上的.没有实际的例子.功夫不负有心人, ...