您的位置:澳门新葡8455最新网站 > 服务器运维 > 举例详解_javascript技巧_脚本之家

举例详解_javascript技巧_脚本之家

发布时间:2019-12-31 04:27编辑:服务器运维浏览(128)

    cookie很实用的多少个效率,能够判别有些状态,在品种中使用率相当的高复制代码 代码如下: function setCookie { var Days = 30; var exp = new Date(卡塔尔; exp.setTime + Days*24*60*60*1000); document.cookie = name + "="+ escape + ";expires=" + exp.toGMTString(); var strsec = getsec; var exp = new Date(); exp.setTime + strsec*1); document.cookie = name + "="+ escape + ";expires=" + exp.toGMTString(); } //读取cookies function getCookie { var arr,reg=new RegExp"+name+"=; if(arr=document.cookie.match return ; else return null; } //删除cookies function delCookie { var exp = new Date(); exp.setTime; var cval=getCookie document.cookie= name + "="+cval+";expires="+exp.toGMTString(); }

    复制代码 代码如下: //JS操作cookies方法! //写cookies function setCookie { var Days = 30; var exp = new Date(); exp.setTime + Days*24*60*60*1000卡塔尔国; document.cookie = name + "="+ escape + ";expires=" + exp.to放线菌壮观素TString(State of Qatar; } //读取cookies function getCookie { var arr,reg=new RegExp"+name+"=; if(arr=document.cookie.match return unescape; else return null; } //删除cookies function delCookie { var exp = new Date(卡塔尔; exp.setTime; var cval=getCookie document.cookie= name + "="+cval+";expires="+exp.to克林霉素TString(State of Qatar; } //使用示例 setCookie; alert; //就算必要设定自定义过期日子 //那么把上边的setCookie 函数换来上面四个函数就ok; //程序代码 function setCookie2{ var strsec = getsec; var exp = new Date(State of Qatar; exp.setTime + strsec*1); document.cookie = name + "="+ escape + ";expires=" + exp.toGMTString(); } function getsec; var str1=str.substring*1; var str2=str.substring{ return str1*1000; }else if { return str1*60*60*1000; }else if { return str1*24*60*60*1000; } } //那是有设定过期时间的接受示例: //s20是意味20秒 //h是指时辰,如12时辰则是:h12 //d是运气,30天则:d30 //一时半刻只写了这两种 setCookie2("name2","hayden2","s20"卡塔尔; alert; 以下是多少个比超级多如牛毛的好用的函数: 复制代码 代码如下: function Get库克ieVal //获得Cookie解码后的值 { var endstr = document.cookie.indexOf ; if endstr = document.cookie.length; return unescape(document.cookie.substring; } function Set库克ie //设定Cookie值 { var expdate = new Date(State of Qatar; var argv = Set库克ie.arguments; var argc = SetCookie.arguments.length; var expires = ? argv[2] : null; var path = ? argv[3] : null; var domain = ? argv[4] : null; var secure = ? argv[5] : false; if expdate.setTime + ; document.cookie = name + "=" + escape + ? "" : ("; expires="+ expdate.to克拉霉素TString ? "" : + ? "" : 卡塔尔国 + ? "; secure" : ""卡塔尔国; } function DelCookie //删除Cookie { var exp = new Date(State of Qatar; exp.setTime ; var cval = GetCookie ; document.cookie = name + "=" + cval + "; expires="+ exp.to威他霉素TString(卡塔尔国; } function GetCookie //获得Cookie的原始值 { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while { var j = i + alen; if (document.cookie.substring return GetCookieVal ; i = document.cookie.indexOf + 1; if break; } return null; } //测量检验SetCookie; alert);

    本文由澳门新葡8455最新网站发布于服务器运维,转载请注明出处:举例详解_javascript技巧_脚本之家

    关键词: