当前位置:网站首页>记住用户名案例(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>效果:
边栏推荐
- 苏州大学:从PostgreSQL到TDengine
- Summary of redis basics - data types (strings, lists, sets, hashes, sets)
- 【网络原理的概念】
- numpy
- 鸿蒙第四次
- 谷歌实用插件分享
- 请问应该用什么关键字将内容主题设置为 dark 呢
- Depth study of 100 cases - convolution neural network (CNN) to realize the clothing image classification
- LeetCode 899 有序队列[字典序] HERODING的LeetCode之路
- Analysis of the idea of the complete knapsack problem
猜你喜欢
随机推荐
再谈“雷克萨斯”安全装置失效!安全手册疑点重重,网友:细思极恐
Android 技术面试准备(含面试题及答案)
MATLAB Programming and Applications 2.6 Strings
GBase 8c与openGauss是什么关系?
The way of programmer architecture practice: how to design a sustainable evolution system architecture?
下午见!2022京东云数据库新品发布会
Machines need tokens more than people
Machine Learning (Chapter 1) - Feature Engineering
【输出一个整数的的每一位,由高到低输出。使用递归和不使用递归】
干货!一种被称为Deformable Butterfly(DeBut)的高度结构化且稀疏的线性变换
Matplotlib
【二分查找详解外加递归写法】附有全部代码
二叉搜索树(搜索二叉树)模拟实现(有递归版本)
在 Chrome 开发者工具里通过 network 选项模拟网站的离线访问模式
机器学习概述
Web Server 设置缓存响应字段的一些推荐方案
【Star项目】小帽飞机大战(九)
鸿蒙第三次
[Star Project] Little Hat Plane Battle (9)
MATLAB程序设计与应用 2.7 结构数据与单元数据






![LeetCode 899 有序队列[字典序] HERODING的LeetCode之路](/img/95/1b63cfb25b9e0802666114f089fcb8.png)


