Home > Web Front-end > JS Tutorial > body text

How to use sessionStorage in js? Basic usage of sessionStorage

青灯夜游
Release: 2018-10-24 17:00:08
forward
5028 people have browsed it

The content of this article is to introduce how to use sessionStorage in js? Basic usage of sessionStorage. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

sessionStorage is one of the browser data storage methods. It is used to temporarily save the data of the same window. After closing the window, the sessionStorage data will not exist. It is stored in the form of key value pairs.

Basic usage

Save value

sessionStorage.test="1212";
Copy after login

Get value

var test=sessionStorage.test;
Copy after login

Delete

sessionStorage.removeItem("test");
Copy after login

Remember to delete directly

sessionStorage.test=undefined
Copy after login

The last sessionStorage.test will be equal to "undefined" and will not achieve the effect of deletion

Clear Data Clear the data stored in the current session

sessionStorage.clear();
Copy after login

Total number of sessionStorage

sessionStorage.length
Copy after login

Traverse sessionStorage

for(var i=0;i<sessionStorage.length;i++){  
    var key=sessionStorage.key(i);   
    var value=sessionStorage[key];
}
Copy after login

The above is the detailed content of How to use sessionStorage in js? Basic usage of sessionStorage. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template