In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use localStorage and sessionStorage objects". The content in the article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use localStorage and sessionStorage objects".
There is no time limit for the data stored by the localStorage object. After the next day, the second week, or the next year, the data is still available.
Example
LocalStorage.sitename= "Rookie course"
Document.getElementById ("result") [xss_clean] = "website name:" + localStorage.sitename
Instance resolution:
Use key= "sitename" and value= "rookie tutorial" to create a localStorage key / value pair.
Retrieve the value with the key value "sitename" and insert the data into the element of id= "result".
The above example can also be written as follows:
/ / Storage
LocalStorage.sitename= "Rookie course"
/ / find
Document.getElementById ("result") [xss_clean] = localStorage.sitename
Remove "sitename" from localStorage:
LocalStorage.removeItem ("sitename")
The same API can be used for both localStorage and sessionStorage. The following are commonly used (take localStorage as an example):
Save data: localStorage.setItem (key,value)
Read data: localStorage.getItem (key)
Delete individual data: localStorage.removeItem (key)
Delete all data: localStorage.clear ()
Get the key:localStorage.key (index) of an index
Tip: key / value pairs are usually stored as strings, and you can convert this format as needed.
The following example shows the number of times a user clicks a button.
The string values in the code are converted to numeric types:
Example
If (localStorage.clickcount)
{
LocalStorage.clickcount=Number (localStorage.clickcount) + 1
}
Else
{
LocalStorage.clickcount=1
}
Document.getElementById ("result") [xss_clean] = "you have clicked the button" + localStorage.clickcount + "times"
SessionStorage object
The sessionStorage method stores data for a session. When the user closes the browser window, the data is deleted.
How to create and access a sessionStorage:
Example
If (sessionStorage.clickcount)
{
SessionStorage.clickcount=Number (sessionStorage.clickcount) + 1
}
Else
{
SessionStorage.clickcount=1
}
Document.getElementById ("result") [xss_clean] = "you have clicked this button in this session" + sessionStorage.clickcount + "times"
Thank you for your reading, the above is the content of "how to use localStorage and sessionStorage objects". After the study of this article, I believe you have a deeper understanding of how to use localStorage and sessionStorage objects, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 264
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.