当前位置:网站首页>记住用户名案例(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>效果:
边栏推荐
猜你喜欢

下午见!2022京东云数据库新品发布会

干货!一种被称为Deformable Butterfly(DeBut)的高度结构化且稀疏的线性变换

Skills required to be a good architect: How to draw a system architecture that everyone will love?What's the secret?Come and open this article to see it!...

【二分查找详解外加递归写法】附有全部代码

FR9811S6 SOT-23-6 23V,2A同步降压DC/DC转换器

APENFT FOUNDATION官宣2022艺术梦想基金主题征集

深度学习经典网络 -- Inception系列(稀疏结构)

多态详细讲解(简单实现买票系统模拟,覆盖/重定义,多态原理,虚表)
![[LeetCode—Question 2 Sum of Two Numbers Detailed Code Explanation ] The source code is attached, which can be copied directly](/img/19/a3f58d5a1150d99571205a7e2f7345.png)
[LeetCode—Question 2 Sum of Two Numbers Detailed Code Explanation ] The source code is attached, which can be copied directly

卷起来!阿里高工携18位高级架构师耗时57天整合的1658页面试总结
随机推荐
程序员架构修炼之道:如何设计出可持续演进的系统架构?
混合型界面:对话式UI的未来
Skills required to be a good architect: How to draw a system architecture that everyone will love?What's the secret?Come and open this article to see it!...
numpy
云原生 Dev0ps 实践
【输出一个整数的的每一位,由高到低输出。使用递归和不使用递归】
微信小程序获取用户手机号码
【二分查找详解外加递归写法】附有全部代码
「全球数字经济大会」登陆 N 世界,融云提供通信云服务支持
卷起来!阿里高工携18位高级架构师耗时57天整合的1658页面试总结
优炫数据库在linux平台下服务启动失败的原因
【冒泡排序以及奇数偶数排列】
Web Server 设置缓存响应字段的一些推荐方案
What is the ERC20 token standard?
gbase在轨道交通一般都采用哪种高可用架构?
如何将Oracle/MySQL中的数据迁移到GBase 8c中?
Binary search tree (search binary tree) simulation implementation (there is a recursive version)
ScrollView嵌套RecyclerView滚动冲突
Advanced use of MySQL database
2022年五面蚂蚁、三面拼多多、字节跳动最终拿offer入职拼多多