qzgx.net
当前位置:首页 >> js获取CookiE的值 >>

js获取CookiE的值

获取Cookie函数:function getCookie(cookieName) { var strCookie = document.cookie; var arrCookie = strCookie.split("; "); for(var i = 0; i < arrCookie.length; i++){ var arr = arrCookie[i].split("="); if(cookieName == arr[0]){ return arr[1]; } } return ""; }调用:var user_id = getCookie("selected_prj_id");

cookie是一个对象,类似于java里面的map,有着key和value的值.你通过document.cookie="name="+username;来设置cookie.

读取属于当前文档的所有cookies var allcookies = document.cookie; 定义一个函数,用来读取特定的cookie值. function getCookie(cookie_name) { var allcookies = document.cookie; var cookie_pos = allcookies.indexOf(cookie_name); //索引

function getCookie(cookie_name){var allcookies = document.cookie;var cookie_pos = allcookies.indexOf(cookie_name); //索引的长度 // 如果找到了索引,就代表cookie存在,// 反之,就说明不存在.if (cookie_pos != -1){// 把cookie_pos放在

首先JS设置cookie:假设在A页面中要保存变量username的值("jack")到cookie中,key值为name,则相应的JS代码为:document.cookie="name="+username;JS读取cookie:var username=document.cookie.split(";")[0].split("=")[1];

白菜编辑部 function readCookie (name) { var cookieValue = ""; var search = name + "="; if (document.cookie.length > 0) { offset = document.cookie.indexOf (search); if (offset != -1) { offset += search.length; end = document.cookie.indexOf (";

function getCookie(Name) { var search = Name + "=" if(document.cookie.length > 0) { offset = document.cookie.indexOf(search) if(offset != -1) { offset += search.length end = document.cookie.indexOf(";", offset) if(end == -1) end = document.

这个简单<br>function SetCookie(name,value)//两个参数,一个是cookie的名子,一个是值<br>{<br>var Days = 30; //此 cookie 将被保存 30 天<br>var exp = new Date(); //new Date("December 31, 9998");<br>exp.setTime(exp.getTime() +

document.cookie,然后根据需要提取要用的部分.

用document.cookie 获取当前域名下的cookie.具体代码如下:var mycookie = document.cookie它读出来是一串字符串,包含当前域名下的所有cookie,解析字符串可以得到cookie值document.cookie这个.

网站首页 | 网站地图
All rights reserved Powered by www.qzgx.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com