当前位置:网站首页>记住用户名案例(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>效果:
边栏推荐
- 谷歌实用插件分享
- 如何检索IDC研究报告?
- MATLAB Programming and Applications 2.6 Strings
- Advanced use of MySQL database
- Machine Learning (Chapter 1) - Feature Engineering
- [Star Project] Little Hat Plane Battle (9)
- For invoice processing DocuWare, cast off the yoke of the paper and data input, automatic processing all the invoice received
- fast planner中拓扑路径搜索
- 数字藏品和ICP
- 一文带你弄懂 CDN 技术的原理
猜你喜欢

CADEditorX ActiveX 14.1.X

白帽黑客与留守儿童破壁对“画”!ISC、中国光华科技基金会、光明网携手启动数字安全元宇宙公益展

谷歌实用插件分享

SAP 电商云 Spartacus UI 的 External Routes 设计明细

卷起来!阿里高工携18位高级架构师耗时57天整合的1658页面试总结

出色的移动端用户验证

3分钟实现内网穿透(基于ngrok实现)

Why is the new earth blurred, in-depth analysis of white balls, viewing pictures, and downloading problems

MapReduce中ETL数据清洗案例

MySQL database combat (1)
随机推荐
For invoice processing DocuWare, cast off the yoke of the paper and data input, automatic processing all the invoice received
苏州大学:从PostgreSQL到TDengine
【Star项目】小帽飞机大战(九)
机器学习(第一章)—— 特征工程
"Global Digital Economy Conference" landed in N World, Rongyun provides communication cloud service support
Cross-chain bridge protocol Nomad suffers hacker attack, losing more than $150 million
谷歌实用插件分享
下午见!2022京东云数据库新品发布会
C - 为什么指针常常初始化为 NULL?
Boolean 与numeric 无法互转
QT with OpenGL(Shadow Mapping)(面光源篇)
使用.NET简单实现一个Redis的高性能克隆版(一)
The way of programmer architecture practice: how to design a sustainable evolution system architecture?
混合型界面:对话式UI的未来
MATLAB Programming and Applications 2.6 Strings
Programmers architecture practice way: software architecture basic concepts and thinking
关于OPENSSL的问题
二叉搜索树(搜索二叉树)模拟实现(有递归版本)
numpy
LP流动性挖矿DAPP系统开发丨流动性挖矿功能原理及说明