富贵资源网 Design By www.hznty.com
主要是通过对document.cookie字符串的分析来进行功能的组装的。
温习一下javascript中对cookie的操作:
增加cookie可以用document.cookie="userId=111";来实现
完整版可以用:document.cookie="userId=111;domain=.google.com;path=\;secure=secure;expire="+date.toGMTString();
可以设置cookie的过期时间,域名,路径
需要删除只要将expire的时间设为现在之前就可以了
现在上我修改的javascript.cookie.js的类
复制代码 代码如下:
/*
cookie helper class
easy to write,get,delete
*/
var myCookie={
get:function(name){
if(typeof name != "undefined")
{
//if name given call the get value function
return myCookie_get(name);
}else{
//if name is not given,i want get all the cookie item
return myCookie_getAll();
}
},
add:function(name,value,options){
//write the cookie
myCookie_add(name,value,options);
},
delete:function(name){
//delete the cookie
myCookie_add(name,null);
}
}
String.prototype.Trim = function()
{
return this.replace(/^\s+/g,"").replace(/\s+$/g,"");
}
/*
cookie write function
@name:the cookie name not null
@value:the cookie value null==delete the cookie
@option:{"expires":expire time;"path":/;"domain":localhost;"secure":secure}
*/
function myCookie_add(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();
date.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
}
var path = options.path ? '; path=' + options.path : '';
var domain = options.domain ? '; domain=' + options.domain : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
}
}
/*
get the name cookie
@name:the cookie's name
*/
function myCookie_get(name)
{
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].Trim();
// 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;
}
/*
get all the cookie return as a json
*/
function myCookie_getAll()
{
var cookieArray = new Array();
var str="";
var temp;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].Trim();
temp=cookie.split('=');
//take the
cookieArray.push("{\"name\":\""+decodeURIComponent(temp[0])+"\",\"value\":\""+decodeURIComponent(temp[1])+"\"}");
}
str=cookieArray.join(",");
}
str="["+str+"]";
return eval('('+str+')');
}
调用也是相当简单
复制代码 代码如下:
myCookie.add("useraccount","admin",{"expires":5});//加入一个期限为5天的cookie
alert(myCookie.get("useraccount"));//取出cookie
cookies=myCookie.get();//得到所有的cookie
for(var i=0;i<cookies.length;i++)
{
alert(cookies[i]["name"]+":"+cookies[i]["value"]);
}
myCookie.delete("useraccount");//删除刚刚添加的cookie
alert(myCookie.get("useraccount"));
温习一下javascript中对cookie的操作:
增加cookie可以用document.cookie="userId=111";来实现
完整版可以用:document.cookie="userId=111;domain=.google.com;path=\;secure=secure;expire="+date.toGMTString();
可以设置cookie的过期时间,域名,路径
需要删除只要将expire的时间设为现在之前就可以了
现在上我修改的javascript.cookie.js的类
复制代码 代码如下:
/*
cookie helper class
easy to write,get,delete
*/
var myCookie={
get:function(name){
if(typeof name != "undefined")
{
//if name given call the get value function
return myCookie_get(name);
}else{
//if name is not given,i want get all the cookie item
return myCookie_getAll();
}
},
add:function(name,value,options){
//write the cookie
myCookie_add(name,value,options);
},
delete:function(name){
//delete the cookie
myCookie_add(name,null);
}
}
String.prototype.Trim = function()
{
return this.replace(/^\s+/g,"").replace(/\s+$/g,"");
}
/*
cookie write function
@name:the cookie name not null
@value:the cookie value null==delete the cookie
@option:{"expires":expire time;"path":/;"domain":localhost;"secure":secure}
*/
function myCookie_add(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();
date.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
}
var path = options.path ? '; path=' + options.path : '';
var domain = options.domain ? '; domain=' + options.domain : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
}
}
/*
get the name cookie
@name:the cookie's name
*/
function myCookie_get(name)
{
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].Trim();
// 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;
}
/*
get all the cookie return as a json
*/
function myCookie_getAll()
{
var cookieArray = new Array();
var str="";
var temp;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].Trim();
temp=cookie.split('=');
//take the
cookieArray.push("{\"name\":\""+decodeURIComponent(temp[0])+"\",\"value\":\""+decodeURIComponent(temp[1])+"\"}");
}
str=cookieArray.join(",");
}
str="["+str+"]";
return eval('('+str+')');
}
调用也是相当简单
复制代码 代码如下:
myCookie.add("useraccount","admin",{"expires":5});//加入一个期限为5天的cookie
alert(myCookie.get("useraccount"));//取出cookie
cookies=myCookie.get();//得到所有的cookie
for(var i=0;i<cookies.length;i++)
{
alert(cookies[i]["name"]+":"+cookies[i]["value"]);
}
myCookie.delete("useraccount");//删除刚刚添加的cookie
alert(myCookie.get("useraccount"));
富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。