How to get the value of SessionStorage using JS
This article introduces you to using js to obtain the value in sessionstorage. First, it is obtained to output the obtained information or alert(). Secondly, in a static page, using sessionStorage is equivalent to using sessionStorage in a dynamic page. It's the same as connecting to the database. Please refer to this article for details.
The meaning of obtaining sessionStorage
First obtain it in order to output the obtained information. Or alert(); it is easy to see,
Secondly, in a static page, using sessionStorage is equivalent to connecting to the database in a dynamic page
For example: my last article For the project that adds a carriage return event to the button button, you can use sessionStorage in js to obtain the information entered on the page, and you can also obtain the data calculated in the background and display it.
Not much nonsense, it’s important to look at the code:
Specific implementation
<script type="text/javascript"> function login(){ var username=window.document.getElementById("username").value; var password=window.document.getElementById("password").value; if(password=="123456") { window.sessionStorage.setItem("username", username); window.location.href="../index1.html" rel="external nofollow" ; }else{ alert("密码错误请输入正确的密码,例如:123456!"); return false; } } </script> <input type="text" id="username" class="11" placeholder="请输入真实姓名"/> <input type="password" id="password" placeholder="请输入密码(默认密码123456)"/> <input type="button" value="登录考试" onclick="login()">
The above code is to obtain the value of username and Pass to the next interface
and get the password value and compare it with the pre-set one. The difference is that if there is an error, you cannot log in
<script> $(function () { var username= window.sessionStorage.getItem("username") $("#yhm").html("登录用户:"+username) $("#name").html(username) if(window.sessionStorage.getItem("username")===null){ alert("您还没有登录,请登录后重试!") window.location.href="Pages/index.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" ; } $("#esc").on("click",function(){ window.sessionStorage.clear(); window.location.href="Pages/index.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" ; }); }) </script>
Get the value entered on the previous page and display it in the corresponding position
<p id="yhm"></p>
And determine whether there is a sessionStorage value. If not, automatically return to the login page and make corresponding prompts
Clear the sessionStorage value after the click event is triggered
<script> $("#esc").on("click",function(){ window.sessionStorage.clear(); window.location.href="Pages/index.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" ; }); </script>
When The clear event is triggered when the button with the id esc is clicked
<button id="esc" style="background-color: #FF0000">退出考试系统</button>
and it will automatically return to the login interface
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
How to use the loading progress plug-in with pace.js and NProgress.js (detailed tutorial)
In Vue components About custom events (detailed tutorial)
PHP closures and anonymous functions (detailed tutorial)
How to use three in the WeChat applet Cascading selector
How to use jquery to achieve accordion effects
The above is the detailed content of How to get the value of SessionStorage using JS. 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



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

How to use PHP and JS to create a stock candle chart. A stock candle chart is a common technical analysis graphic in the stock market. It helps investors understand stocks more intuitively by drawing data such as the opening price, closing price, highest price and lowest price of the stock. price fluctuations. This article will teach you how to create stock candle charts using PHP and JS, with specific code examples. 1. Preparation Before starting, we need to prepare the following environment: 1. A server running PHP 2. A browser that supports HTML5 and Canvas 3

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

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.

The main advantages of HTML5 include: Semantic markup: clearly conveys content structure and meaning. Multimedia support: native playback of video and audio. Canvas: Create motion graphics and animations. Local Storage: Client stores data and accesses it across sessions. Geolocation: Obtain the user's geographical location information. WebSockets: Continuous connection between browser and server. Mobile Friendly: Works on a variety of devices. Security: CSP and CORS protect against cyber threats. Ease of use: Easy to learn and use. Support: Extensive support for all major browsers and devices.

What are the three ways to set up caching in HTML? In web development, in order to improve user access speed and reduce server load, we can reduce web page loading time by setting cache. Next, I will introduce you to three commonly used HTML cache methods in detail and provide specific code examples. Method 1: Set the cache through the HTTP response header. "Cache-Control" and "Expires" in the HTTP response header are two commonly used attributes for setting cache. By setting these two properties, you can

How to use JS and Baidu Map to implement the function of adding custom place markers to the map. Introduction: Baidu Map is a very commonly used map service. It provides a wealth of map display and interactive functions, including adding custom place markers. Using JS and Baidu Map API, we can easily implement the function of adding custom location markers on the map. The following is a specific code example: Step 1: Preparation First, import the Baidu Map API file in your HTML file, as follows Shown: <scripttype
