jquery实现cookie登录记住用户名密码问题,只需在页面写上相应js方法后台不用做任何处理,下次登录就能记住用户名和密码
先来介绍关于jquery读取cookie方法
example $.cookie(’the_cookie’, ‘the_value’);
设置cookie的值
example $.cookie(’the_cookie’, ‘the_value’, {expires: 7, path: ‘/’, domain: ‘jquery.com’, secure: true});
新建一个cookie 包括有效期 路径 域名等
example $.cookie(’the_cookie’, ‘the_value’);
新建cookie
example $.cookie(’the_cookie’, null);
删除一个cookie
看一个dz遍历cookie方法
分割的数组的处理
function getcookie(name) {
var cookie_start = document.cookie.indexof(name);
var cookie_end = document.cookie.indexof(";", cookie_start);
return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}
function setcookie(cookiename, cookievalue, seconds, path, domain, secure) {
var expires = new date();
expires.settime(expires.gettime() + seconds);
document.cookie = escape(cookiename) + '=' + escape(cookievalue)
+ (expires ? '; expires=' + expires.togmtstring() : '')
+ (path ? '; path=' + path : '/')
+ (domain ? '; domain=' + domain : '')
+ (secure ? '; secure' : '');
}
好了费话说了一大堆了现在我们进来正题
public static void showcookies()
{
int16 i;
httpcookiecollection cookies = system.web.httpcontext.current.request.cookies;
for (i = 0; i < cookies.count; i++)
{
httpcookie cookie = cookies.get(i);
system.web.httpcontext.current.response.write("cookie名称: " + cookie.name + "<br/>");
system.web.httpcontext.current.response.write("值=: " + cookie.value + "<br/>");
system.web.httpcontext.current.response.write("expires期限: " + cookie.expires.tostring() + "<br/>");
system.web.httpcontext.current.response.write("<hr/>");
// system.web.httpcontext.current.response.write ("domain网域:" + cookie.domain + "<br/>");
// system.web.httpcontext.current.response.write ("path路径:" + cookie.path + "<br/>");
//system.web.httpcontext.current.response.write ("secure保密:" + cookie.secure + "<br/>");
}
system.web.httpcontext.current.response.write("共有 " + cookies.count + " 个cookie<br/>");
}
public static void deleteallcookies()
{
int16 i;
httpcookiecollection cookies = system.web.httpcontext.current.request.cookies;
for (i = 0; i < cookies.count; i++)
{
httpcookie cookie = cookies.get(i);
cookie.value = "";
cookie.expires = datetime.now.adddays(-365);
system.web.httpcontext.current.response.cookies.set(cookie);}
system.web.httpcontext.current.response.write("共有 " + cookies.count + " 个cookie被删除<br/>");/* cookies.clear(); */
}
public static void clearallcookies()
{
int16 i;
httpcookiecollection cookies = system.web.httpcontext.current.request.cookies;
for (i = 0; i < cookies.count; i++)
{
httpcookie cookie = cookies.get(i);
cookie.value = "";
system.web.httpcontext.current.response.cookies.set(cookie);
}
system.web.httpcontext.current.response.write("共有 " + cookies.count + " 个cookie被清空<br/>");
}
jquery cookie插件下载地址
http://plugins.jquery.com/project/cookie