function setCookie(name,value,expries)
{
var curcookie = name + "=" + encodeURI(value)
+((expires) ";expires=" + expirestoGMTString() : "")
+((path) ";path=" + path : "")
documentcookie = curcookie;
}
function getCookie(name)
{
if(documentcookielength > 0)
{
start = documentcookieindexOf(name + "=");
if( start != -1)
{
start = start + namelength + 1;
end = documentcookieindexOf(";",start);
if( end == -1)
{
end = documentcookielength;
}
}
return decodeURI(documentcookiesubstring(start,end));
}
return "";
}
function Deletecookie (name) { //删除名称为name的Cookie
var exp = new Date();
expsetTime (expgetTime() - 1);
var cval = GetCookie (name);
documentcookie = name + "=" + cval + "; expires=" + exptoGMTString();
}
function Clearcookie() //清除COOKIE
{
var temp=documentcookiesplit(";");
var loop3;
var ts;
for (loop3=0;loop3 {
ts=temp[loop3]split("=")[0];
if (tsindexOf(’mycat’)!=-1)
DeleteCookie(ts); //如果ts含“mycat”则执行清除
}
}
if(username=="" || userid==""){
document表单名action="需要提交的路径";
document表单名submit();
}
这样子就可以判断了啊 为什么你要利用cookies迷糊
ASP获取cookies内的参数不会
用js向cookie中保存数据、获取数据的方法如下:
function GetCookieVal(offset)
//获得Cookie解码后的值
{
var endstr = documentcookieindexOf (";", offset);
if (endstr == -1)
endstr = documentcookielength;
return unescape(documentcookiesubstring(offset, endstr));
}
//---------------------------
function SetCookie(name, value)
//设定Cookie值
{
var expdate = new Date();
var argv = SetCookiearguments;
var argc = SetCookieargumentslength;
var expires = (argc > 2) argv[2] : null;
var path = (argc > 3) argv[3] : null;
var domain = (argc > 4) argv[4] : null;
var secure = (argc > 5) argv[5] : false;
if(expires!=null) expdatesetTime(expdategetTime() + ( expires 1000 ));
documentcookie = name + "=" + escape (value) +((expires == null) "" : ("; expires="+ expdatetoGMTString()))
+((path == null) "" : ("; path=" + path)) +((domain == null) "" : ("; domain=" + domain))
+((secure == true) "; secure" : "");
}
//---------------------------------
function DelCookie(name)
//删除Cookie
{
var exp = new Date();
expsetTime (expgetTime() - 1);
var cval = GetCookie (name);
documentcookie = name + "=" + cval + "; expires="+ exptoGMTString();
}
//------------------------------------
function GetCookie(name)
//获得Cookie的原始值
{
var arg = name + "=";
var alen = arglength;
var clen = documentcookielength;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (documentcookiesubstring(i, j) == arg)
return GetCookieVal (j);
i = documentcookieindexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
SetCookie("username1",99);
alert(GetCookie("username1"));
// 函数名称: getCookie
// 函数功能: 读取cookie函数
// 入口参数: Name:cookie名称
function getCookie(Name) {
var search = Name + "=" ;
if(documentcookielength > 0) {
offset = documentcookieindexOf(search) ;
if(offset > -1) {
offset += searchlength ;
end = documentcookieindexOf(";", offset)
if(end > -1) {
end = documentcookielength ;
}
return unescape(documentcookiesubstring(offset, end)) ;
} else {
return "" ;
}
}
}
以上就是关于求一段js *** 作cookie的代码全部的内容,包括:求一段js *** 作cookie的代码、JS读取COOKIES并判断、如何用js向cookie中保存数据、取数据等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)