<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script>
window.onload = function ()
{
var ologin = document.getElementById('login');
var odel = document.getElementById('del');
var ousername = document.getElementById('username'); if(getcookie('username'))
{
ousername = getcookie('username');
} ologin.onclick = function()
{
alert('登陆成功')
setcookie('username',ousername.value,5);
} odel.onclick = function ()
{
removecookie('username');
ousername.value = ''; } function getcookie (key)
{
var arr1 = document.cookie.split(';');
for(var i = 0; i < arr1.length; i++)
{
var arr2 = arr1[i].split('=');
if(key == arr2[0])
{
return decodeURI(arr2[1]);
}
}
} function getcookie (key)
{
var arr1 = document.cookie.split(';');
for(var i = 0; i < arr1.length; i++)
{
var arr2 = arr1[i].split('=');
if(key == arr2[0])
{
return decodeURI(arr2[1]);
}
}
} function setcookie(key,value,t)
{
var oDate = new Date();
oDate.setDate(oDate.getDate()+t);
document.cookie = key + ':' + value + ';expires =' + oDate.toGMTString();
} function removecookie(key)
{
setcookie(key,'',-1);
}
};
</script>
</head> <body>
<input type="text" id="username">
<input type="button" id="login" value="登陆">
<input type="button" id="del" value="删除">
</body>
</html>

dom cookie记录用户名的更多相关文章

  1. cookie记录用户名

    在说如何用cookie记录用户名之前,我们先来说说cookie的工作原理: cookie : 存储数据,当用户访问了某个网站(网页)的时候,我们就可以通过cookie来像访问者电脑上存储数据 ; 1. ...

  2. cookie记录用户名和密码

    getAttribute和getParameter的区别: request.getAttribute():是request时设置的变量的值,用request.setAttribute("na ...

  3. 用cookie记住用户名

    有时候,我们在做登陆框时会有个复选框选择请记住我,或者有时候会遇到一些弹出框说下次不再提醒,此功能我们可以用js中的cookie实现此功能 下面记录一下如何实现该功能: 利用cookie记录用户名 1 ...

  4. cookie记录浏览记录

    cookie记录浏览记录 HashMap也是我们使用非常多的Collection,它是基于哈希表的 Map 接口的实现,以key-value的形式存在.在HashMap中,key-value总是会当做 ...

  5. cookie记录用户的浏览商品的路径

    在电子商务的网站中,经常要记录用户的浏览路径,以判断用户到底对哪些商品感兴趣,或者哪些商品之间存在关联. 下面将使用cookie记录用户的浏览过的历史页面.该网站将每个页面的标题保存在该页面的$TIT ...

  6. cookie记录横向滚动条位置

    一.Css <style type="text/css"> #x{ width: 100%; white-space: nowrap; overflow-x: scro ...

  7. 通过cookie记录,设置页面访问的跳转页

    通过cookie记录,设置页面访问的跳转页 转载自:http://blog.csdn.net/yixiao_naihe/article/details/26679515. 目的: 1.访问fm.htm ...

  8. cookie记住用户名密码

    <script src="js/jquery.cookie.js" type="text/javascript"></script> $ ...

  9. JS利用cookie记录当前位置实现刷新页面后还可以保持菜单栏的展开或闭合

    代码如下,重点是JS部分的代码(部分样式引用的是Bootstrapt中的):   <style> .sidebar-menu .special{ font-size: 16px; marg ...

随机推荐

  1. Oracle HRMS API – Create Employee

    -- Create Employee -- ------------------------- DECLARE   lc_employee_number            PER_ALL_PEOP ...

  2. leetcode Database3

    一.Rank Scores Write a SQL query to rank scores. If there is a tie between two scores, both should ha ...

  3. create-maximum-number(难)

    https://leetcode.com/problems/create-maximum-number/ 这道题目太难了,花了我很多时间.最后还是参考了别人的方法.还少加了个greater方法.很难. ...

  4. @Inject.@Resource.@Autowired 的区别

    @Inject:Struts2的注解, @Resource : J2EE提供,用于注入,( j2ee提供的 ) 默认按名称装配,@Resource(name="beanName") ...

  5. hdu 5091(线段树+扫描线)

    上海邀请赛的一道题目,看比赛时很多队伍水过去了,当时还想了好久却没有发现这题有什么水题的性质,原来是道成题. 最近学习了下线段树扫描线才发现确实是挺水的一道题. hdu5091 #include &l ...

  6. Centos 6.5LAMP服务器(Apache+PHP+MySQL)的搭建

    1.首先看下你的防火墙是否处于开启状态,如果是开启状态,按照如下方法来配置你的防火墙(如果你在安装虚拟机时就没有开启过防火墙,那么这一步就省略了): 1.配置防火墙,开启80端口.3306端口 vi ...

  7. 维护没有源代码,float改成double

    float f= 931340.31f; Console.WriteLine(f.ToString("#,###,##0.00")); 返回 931,340.30 ,float 1 ...

  8. 转:Emmet:快速编写HTML,CSS代码的有力工具

    http://www.cnblogs.com/xiazdong/p/3562179.html  试着用用

  9. 同步内核缓冲区sync、fsync和fdatasync函数

    转自http://www.2cto.com/os/201409/339460.html 同步内核缓冲区 1.缓冲区简介 人生三大错觉之一:在调用函数write()时,我们认为该函数一旦返回,数据便已经 ...

  10. erl0007 - erlang 远程节点连接的两种方式

    启动连接:erl -setcookie abc -name xxx@192.168.x.x -remsh xxx@192.168.x.y 退出:ctrl + g,q 参考:http://www.cnb ...