How to use JS code to remember account and password
This time I will show you how to remember account and password with JS code. What are the precautions for remembering account and password with JS code? The following is a practical case, let’s take a look.
Many login functions have a "remember password" function, which is actually nothing more than readingcookie.
<!-- 登陆表单 --><form method="post" autocomplete="off" onsubmit="return check()"> <!-- 用户名输入 --> <input type="text" name="username" id="username" required="required" > <!-- 密码输入,禁用自动填充 --> <input type="password" autocomplete="new-password" name="password" id="password" required="required"> <!-- 是否记住密码复选框 --> <input type="checkbox" id="isRmbPwd" name="isRmbPwd" checked="checked">记住密码 <!-- 提交按钮 --> <input type="submit" value="提交"></form>
function check (){ //获取表单输入:用户名,密码,是否保存密码 var username = document.getElementById("username").value.trim() ; var password = document.getElementById("password").value.trim() ; var isRmbPwd = document.getElementById("isRmbPwd").checked ; //判断用户名,密码是否为空(全空格也算空) if ( username.length != 0 && password.length != 0 ) { //若复选框勾选,则添加Cookie,记录密码 if ( isRmbPwd == true ) { setCookie ( "This is username", username, 7 ) ; setCookie ( username, password, 7 ) ; } //否则清除Cookie else { delCookie ( "This is username" ) ; delCookie ( username ) ; } return true ; } //非法输入提示 else { alert('请输入必填字段!!!') return false ; } }
//将function函数赋值给onload对象window.onload = function (){ //从Cookie获取到用户名 var username = getCookie("This is username") ; //如果用户名为空,则给表单元素赋空值 if ( username == "" ) { document.getElementById("username").value="" ; document.getElementById("password").value="" ; document.getElementById("isRmbPwd").checked=false ; } //获取对应的密码,并把用户名,密码赋值给表单 else { var password = getCookie(username) ; document.getElementById("username").value = username ; document.getElementById("password").value = password ; document.getElementById("isRmbPwd").checked = true ; } }
How to use base64 encoding for html pictures instead
How to implement scrolling fonts and pictures in marquee elements Effect
The above is the detailed content of How to use JS code to remember account and password. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



As a content-rich social e-commerce platform, Xiaohongshu has attracted a large number of users. For those who want to conduct multiple businesses on Xiaohongshu, it is particularly important to have multiple accounts. So, how does Xiaohongshu have multiple accounts? How can we make these accounts have traffic? This article will analyze these issues in detail and provide you with helpful guidance. 1. How to have multiple accounts on Xiaohongshu? When registering a Xiaohongshu account, you can choose to register multiple accounts using different mobile phone numbers or email addresses in order to have multiple accounts. Real-name authentication is an effective measure to improve account security and credibility. It is recommended to conduct real-name authentication for each account, so that the account will be more authoritative and credible. 3. Improve the information: Improve the information of each account, including personal homepage, header

Google Chrome is a web browsing tool used by many people. In order to make it more convenient to use, some users want to log in to their Google account first, but a prompt that the account cannot be logged in appears. Regarding this issue, many users do not know what to do. How to solve it, then today the editor will share the complete solution with you. I hope that the content of today’s software tutorial can help the majority of users. Google account shows that you cannot log in. Solution: 1. Click on a browser on the desktop and you will see something like this after opening it. 2. If a login pops up at this time, click it. If you can't see it, click the upper right corner. 3. Click Login, then enter your account number. You do not need to enter the account after @, and click Next. 4. Enter the password,

In the digital age, Xiaohongshu has become a platform for many people to share their lives and discover good things. Over time, we may need to change the mobile phone number on the account. So, how to change Xiaohongshu’s mobile phone number? 1. How to change the mobile phone number of Xiaohongshu account? 1. Log in to your Xiaohongshu account and enter the “My” page. 2. Click "..." in the upper right corner and select "Settings". 3. On the settings page, find the "Account and Security" option and click to enter. 4. On the Account and Security page, find the "Mobile Phone Number" option and click to enter. 5. At this time, the page will display the current mobile phone number, click "Change Mobile Number". 6. Enter the new mobile phone number, receive the verification code, and fill it out. 7. Set a new password to ensure account security. 8. After completing the above steps,

As a platform that integrates community, content and e-commerce, Xiaohongshu has attracted the attention of many creators and users. Some users want to have two Xiaohongshu accounts to better manage and operate different types of content. This article will explore how to create two Xiaohongshu accounts and explore the potential benefits of this approach for creators. 1. How to have two Xiaohongshu accounts? Registering a new account is very simple. Just download the Xiaohongshu APP from the mobile app store, then fill in the relevant information according to the prompts and set the nickname, avatar and password. 2. Log in to the original account: After registering a new account, you need to log out of the Xiaohongshu APP and then log in to your original account again. 3. Switch accounts: In the Xiaohongshu APP, click "My" in the lower right corner, then click the avatar and select "

What should I do if my Kuaishou account is activated abnormally? If your Kuaishou account is abnormal and needs to be activated, you can try the following steps to solve the problem: Try to log in again: First, make sure to log in to your Kuaishou account again with the accurate username and password. Verify the accuracy of the information entered. 2. Check network connection: Make sure your device is connected to the Internet properly. Sometimes, network problems may cause abnormal account login. 3. Check account status: If your account is banned or frozen by Kuaishou due to violations or other reasons, you need to contact Kuaishou's customer support department to solve the problem. They may require you to provide identity verification or other information to activate your account. 4. Verification code or mobile phone verification: Kuaishou may require you to conduct mobile phone verification or enter a verification code to ensure the security of your account.

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

In today's society, mobile phones have become an indispensable part of our lives. As an important tool for our daily communication, work, and life, WeChat is often used. However, it may be necessary to separate two WeChat accounts when handling different transactions, which requires the mobile phone to support logging in to two WeChat accounts at the same time. As a well-known domestic brand, Huawei mobile phones are used by many people. So what is the method to open two WeChat accounts on Huawei mobile phones? Let’s reveal the secret of this method. First of all, you need to use two WeChat accounts at the same time on your Huawei mobile phone. The easiest way is to

As a popular social e-commerce platform, Xiaohongshu has attracted a large number of users. Many users may encounter the problem of needing to switch accounts when registering Xiaohongshu. So, how to switch accounts on Xiaohongshu without changing the original account? This article will answer this question in detail and help you better use Xiaohongshu. 1. How to switch accounts in Xiaohongshu so that the original account remains unchanged? 1. Open the Xiaohongshu APP and enter the personal center. 2. Click the "Settings" button in the upper right corner to enter the setting interface. 3. In the settings interface, find the "Account and Security" option and click to enter. 4. In the account and security interface, find the "Switch Account" option and click to enter. 5. Enter the password of the original account and confirm the account switch. 6. After the switch is successful, you will return to the personal center of the original account. 2. Xiaohong
