本文地址:http://www.cnblogs.com/PiaoMiaoGongZi/p/4092489.html 转载请注明。

Js获取所有的cookie信息:

var cookiename = document.cookie.split(";");

Js读写cookie值是中文乱码解决办法:

//写入cookie
function SetCookie(name, value) {
var exp = new Date();
exp.setTime(exp.getTime() + 6 * 24 * 60 * 60 * 1000); //6天过期
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
return true;
};
//读取cookie
function getCookie(name) {
var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
if (arr != null) return unescape(arr[2]); return null;
};

其中unescape() 方法是将字符串进行编码,escape()方法是将字符串进行解码。

两个方法详细用法请参考http://www.w3school.com.cn/jsref/jsref_escape.asp

本文地址:http://www.cnblogs.com/PiaoMiaoGongZi/p/4092489.html 转载请注明。

JS读写cookie以及中文乱码解决的更多相关文章

  1. JS获取URL参数中文乱码解决

    var param = window.location.search; var paramArray = parseParams(param); var selectV = decodeURI(par ...

  2. Java读写文件,中文乱码解决

    读文件:使用new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); Strin ...

  3. 近期在调用 calendar.js 的时候出现中文乱码! 解决方式

    近期写一个小项目的时候:在调用 calendar.js  的时候出现中文乱码! 如图所看到的: 原因在于: 我的jsp 页面,指定的是 UTF-8 编码,然而,调用的 calendar.js 的编码确 ...

  4. Node.js 中文乱码解决

    Node.js 中文乱码解决 Node.js 支持中文不太好(实际上是Javascript支持),见<Node.js开发指南>. 要想Node.js正常显示中文,需要两点: 1.js文件保 ...

  5. 【转】asp.net Cookie值中文乱码问题解决方法

    来源:脚本之家.百度空间.网易博客 http://www.jb51.net/article/34055.htm http://hi.baidu.com/honfei http://tianminqia ...

  6. jquery的ajax()函数传值中文乱码解决方法介绍

    jquery的ajax()函数传值中文乱码解决方法介绍,需要的朋友可以参考下 代码如下: $.ajax({ dataType : ‘json', type : ‘POST', url : ‘http: ...

  7. Java 前台后台数据传递、中文乱码解决方法

    1.向前台传递数据;2.向后台传递数据;3.ajax post 提交数据到服务端时中文乱码解决方法;4.数组类型参数传递; 1.向前台传递数据:1.1 字符串数据传递:  这种方式只是单一的向前台传递 ...

  8. ajax()函数传值中文乱码解决方法介绍

    jquery的ajax()函数传值中文乱码解决方法介绍,需要的朋友可以参考下 复制代码 代码如下: $.ajax({ dataType : ‘json',type : ‘POST',url : ‘ht ...

  9. 【python系列】python画报表(Chartkick、Flask)(附中文乱码解决方式)

    chartkick 能够画 javascript 报表, 并且比較美观.可是网上搜了下.非常难找到 python 版本号的,于是查了些资料,摸索了下. 对 Flask 也不非常熟悉,这里就仅仅抛砖引玉 ...

随机推荐

  1. ural 1145. Rope in the Labyrinth

    1145. Rope in the Labyrinth Time limit: 0.5 secondMemory limit: 64 MB A labyrinth with rectangular f ...

  2. Javascript 利用a标签自动解析URL分析网址实例

    /* * @function: 通过a标签解析url标签 * @param:url url参数是字符串,解析的目标 通过IE6-9 chrome Firefox测试 * */ function par ...

  3. Posterior visual bounds retrieval for the Plato framework

    Plato is a MVVM compliant 2D on-canvas graphics framework I've been designing and implementing for d ...

  4. RecyclerView android:layout_width="match_parent" 无效

    使用RecyclerView 时,在xml文件中设置宽度match_parent无效. View view = mInflater.from(mContext).inflate(R.layout.it ...

  5. Leetcode Unique Paths

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...

  6. 转载:移动前端开发之viewport的深入理解

    原文作者:无双 原文链接:http://www.cnblogs.com/2050/p/3877280.html 在移动设备上进行网页的重构或开发,首先得搞明白的就是移动设备上的viewport了,只有 ...

  7. Android -- 简单广播接收与发送(2)--动态注册广播接收器

    1. 效果图

  8. 【Eclipse】修改 编码格式

    eclipse 默认编码居然是GBK,js文件默认编码是ISO-....怎么可以这样呢? 都修改成UTF8的方法: 1.windows->Preferences...打开"首选项&qu ...

  9. 关于transition回调函数的几种写法

    平时工作中经常遇到需要transition动画结束后触发某个功能的问题,但是在映像中好像只见过animate的回调函数, 而transition的很多属性无法在animate中使用,经过一些总结归纳, ...

  10. 初识socket

    socket也叫套接字,用于通信的一个句柄,描述IP与端口信息,程序通过套接字可以向网络发出请求或者应答网络请求. socket起源与unix,而unix/Linux基本哲学之一就是”一切皆文件“,对 ...