当前位置:网站首页>记住用户名案例(js)
记住用户名案例(js)
2022-08-03 11:03:00 【Cap07】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<input type="text" id="username"> <input type="checkbox" name="" id="remember"> 记住用户名
<script>
var username = document.querySelector('#username');
var remember = document.querySelector('#remember');
//先判断有没有输入用户名,如果输入,更新value值为用户名
if (localStorage.getItem('username')) {
username.value = localStorage.getItem('username');
remember.checked = true; //用于下次打开页面时,若用户名已记住,则此框默认勾选
}
//当框改变时,根据情况对localStorage进行相应改变
remember.addEventListener('change', function() {
if (this.checked) {
localStorage.setItem('username', username.value)
} else {
localStorage.removeItem('username');
}
})
</script>
</body>效果:
边栏推荐
- For invoice processing DocuWare, cast off the yoke of the paper and data input, automatic processing all the invoice received
- 3分钟实现内网穿透(基于ngrok实现)
- 混动产品谁更吃香,看技术还是看市场?
- 历史拉链数据处理有人做过吗
- 微信多开批处理(自动获取安装路径)
- Machines need tokens more than people
- 在安装GBase 8c数据库的时候,报错显示“Host ips belong to different cluster”。这是为什么呢?有什么解决办法?
- 本周四晚19:00知识赋能第4期直播丨OpenHarmony智能家居项目之设备控制实现
- 【无标题】函数,对象,方法的区别
- 科普大佬说 | 黑客帝国与6G有什么关系?
猜你喜欢
随机推荐
【LeetCode—第2题 两数之和 代码详解 】附有源码,可直接复制
关于OPENSSL的问题
【AppCube】数字孪生万物可视 | 联接现实世界与数字空间
在 Chrome 开发者工具里通过 network 选项模拟网站的离线访问模式
卷起来!阿里高工携18位高级架构师耗时57天整合的1658页面试总结
3D激光SLAM:LeGO-LOAM---两步优化的帧间里程计及代码分析
GBase 8c与openGauss是什么关系?
跨链桥协议 Nomad 遭遇黑客攻击,损失超 1.5 亿美元
出色的移动端用户验证
MATLAB Programming and Applications 2.6 Strings
智能合约是什么?
Polymorphism in detail (simple implementation to buy tickets system simulation, covering/weight definition, principle of polymorphism, virtual table)
通过GBase 8c Platform安装数据库集群时报错
Analysis of the idea of the complete knapsack problem
【网络原理的概念】
Binary search tree (search binary tree) simulation implementation (there is a recursive version)
Babbitt | Metaverse daily must-read: Players leave, platforms are shut down, and the digital collection market is gradually cooling down. Where is the future of the industry?...
本周四晚19:00知识赋能第4期直播丨OpenHarmony智能家居项目之设备控制实现
How to retrieve IDC research reports?
二叉搜索树(搜索二叉树)模拟实现(有递归版本)








