问题: 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. HDU 5718 Oracle

    如果非零的数小于等于1个,则无解.否则有解. 取出一个最小的非零的数作为一个数,剩下的作为一个数,相加即可. #include<cstdio> #include<cstring> ...

  2. Disassembly1:HelloWorld

    我这里学习汇编语言的思路就是逆向C++源码. 先从最简单的一个程序入手:

  3. 报错:“不是有效的Win32应用程序”的解决办法

    Win7.Win8下用VS2013编译完的程序,拿到32位WindowsXP虚拟机下运行有时候会报错:

  4. PAT1001

    时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B Calculate a + b and output the sum in standard format 计算a+b ...

  5. AdminLTE的使用

    1.AdminLTE的必要配置文件<!-- Tell the browser to be responsive to screen width --> <meta content=& ...

  6. [转]学会Python可以有以下几类工作方向:

    Python开发工程师 :一般需要精通Python编程语言,有Django等框架的使用经验,实习无要求. Python高级工程师 : 北上广深的话,薪金在1万以上,需要精通Linux/Unixg平台, ...

  7. FusionCharts使用问题及解决方法(三)-FusionCharts常见问题大全

    前两篇文章中,我们总结了FusionCharts图表的一些常见问题(FAQ)及解决方法,本文继续讨论FusionCharts使用者常见的一些复杂的报错及解决方法. 当HTML.SWF和JavaScri ...

  8. Efim and Strange Grade

    Efim and Strange Grade time limit per test 1 second memory limit per test 256 megabytes input standa ...

  9. android脚步---Itent.ACTION_PICK ,startActivityForResult

    public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(Intent.A ...

  10. 1025:To the max(DP)

    Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...