JavaScript cookie basic application (method of recording user name)
This article mainly introduces the method of recording user names in the basic application of javascript cookies, involving simple applications of javascript based on cookies for data storage. Friends in need can refer to it
The examples in this article describe the basics of javascript cookies The application's method of recording usernames. Share it with everyone for your reference, the details are as follows:
There is an article about the basics of cookies, which encapsulates cookie.js. Below we use an example to apply this js.
The most common one is to remember the user name. After the user logs in once, the user's account and password are recorded through cookies, so that the next time the page is opened, the user does not need to enter the account and password again. Attached code:
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title>cookie的应用——记住用户名</title> </head> <body> <form action="#" id="myform"> <label for="username">用户名:</label><input type="text" name="username" id="username" /> <label for="userpass">密码:</label><input type="password" name="userpass" id="userpass" /> <input type="submit" value="登录" /> <a href="javascript:;">清除记录</a> </form> </body> </html> <script type="text/javascript" src="cookie.js"></script> <script type="text/javascript"> window.onload = function(){ var oForm = document.getElementById('myform'); var oTxt1 = document.getElementById('username'); var oTxt2 = document.getElementById('userpass'); var oClear = document.getElementsByTagName('a')[0]; oTxt1.value = getCookie('username'); oTxt2.value = getCookie('userpass'); oForm.onsubmit = function(){ setCookie('username',oTxt1.value,30); setCookie('userpass',oTxt2.value,30); } oClear.onclick = function(){ removeCookie('username'); removeCookie('userpass'); oTxt1.value = ''; oTxt2.value = ''; } } </script>
PS: Post the cookie.js in the previous article here for everyone to view:
function setCookie(name,value,hours){ var d = new Date(); d.setTime(d.getTime() + hours * 3600 * 1000); document.cookie = name + '=' + value + '; expires=' + d.toGMTString(); } function getCookie(name){ var arr = document.cookie.split('; '); for(var i = 0; i < arr.length; i++){ var temp = arr[i].split('='); if(temp[0] == name){ return temp[1]; } } return ''; } function removeCookie(name){ var d = new Date(); d.setTime(d.getTime() - 10000); document.cookie = name + '=1; expires=' + d.toGMTString(); }
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Detailed explanation of JavaScript cookie and simple example application (picture and text tutorial)
Understanding and understanding of JavaScript cookie Use
javascript cookieUsage (concept, setting, reading and deletion)
##
The above is the detailed content of JavaScript cookie basic application (method of recording user name). 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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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



Cookies on your computer are stored in specific locations on your browser, depending on the browser and operating system used: 1. Google Chrome, stored in C:\Users\YourUsername\AppData\Local\Google\Chrome\User Data\Default \Cookies etc.

Cookies are usually stored in the cookie folder of the browser. Cookie files in the browser are usually stored in binary or SQLite format. If you open the cookie file directly, you may see some garbled or unreadable content, so it is best to use Use the cookie management interface provided by your browser to view and manage cookies.

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

Cookies on the mobile phone are stored in the browser application of the mobile device: 1. On iOS devices, Cookies are stored in Settings -> Safari -> Advanced -> Website Data of the Safari browser; 2. On Android devices, Cookies Stored in Settings -> Site settings -> Cookies of Chrome browser, etc.

With the popularity of the Internet, we use browsers to surf the Internet have become a way of life. In the daily use of browsers, we often encounter situations where we need to enter account passwords, such as online shopping, social networking, emails, etc. This information needs to be recorded by the browser so that it does not need to be entered again the next time you visit. This is when cookies come in handy. What are cookies? Cookie refers to a small data file sent by the server to the user's browser and stored locally. It contains user behavior of some websites.

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese

The relationship between js and vue: 1. JS as the cornerstone of Web development; 2. The rise of Vue.js as a front-end framework; 3. The complementary relationship between JS and Vue; 4. The practical application of JS and Vue.
