HTML5 Localstorage JS

Source: Internet
Author: User
Tags sessionstorage

HTML5 Localstorage JS

/* HTML5 SessionStorage * // Add the data function SSsetVal (key, val) {if (window. sessionStorage) {// check whether the user enters the key if (key = ''| val ='') {return 0;} sessionStorage. setItem (key, val); alert ('data: '+ key +'-> '+ val +' added successfully '); return 1 ;} else {alert ('local storage not supported '); return 0 ;}// query the specified data function SSgetVal (key) {// check whether the user has entered the key if (key = '') {return 0;} if (window. sessionStorage) {return sessionStorage. getItem (key) ;}else {return 0 ;}// modify the function SSchgVal (key, val) {if (window. sessionStorage) {// check whether the user enters the key if (key = ''| val ='') {return 0;} sessionStorage. setItem (key, val); alert ('data: '+ key +'-> '+ val + 'Modified successfully'); return 1 ;}else {return 0 ;}} // Delete the specified data function SSdelVal (key) {// check whether the user enters the key if (key = '') {return 0;} if (window. sessionStorage) {sessionStorage. removeItem (key); return 1 ;}else {return 0 ;}// traverses all functions SSgetAll () {if (window. sessionStorage) {// checks whether data exists if (sessionStorage. length = 0) {return 0;} var arrKey = new Array () // traverse data for (var I = 0; I
 
  

 

 


  

 

/* HTML5 LocalStorage * // Add the data function LSsetVal (key, val) {if (window. localStorage) {// check whether the user has entered the key if (key = ''| val ='') {return 0;} localStorage. setItem (key, val); showModel ('added successfully'); return 1 ;}else {return 0 ;}// query the specified data function LSgetVal (key) {// check whether the user has entered the key if (key = '') {return 0;} if (window. localStorage) {if (localStorage. getItem (key) {return localStorage. getItem (key) ;}else return 0 ;}else {return 0 ;}// modify the formulated data function LSchgVal (key, val) {if (window. localStorage) {// check whether the user has entered the key if (key = ''| val ='') {return 0;} localStorage. setItem (key, val); return 1 ;}else {return 0 ;}// Delete the specified data function LSdelVal (key) {// check whether the user has entered the key if (key = '') {return 0;} if (window. localStorage) {localStorage. removeItem (key); return 1 ;}else {return 0 ;}// traverse all functions LSgetAll () {if (window. localStorage) {// check whether there is data if (localStorage. length = 0) {// alert ('no items in the current shopping cart; add them now '); return 0;} var arrKey = new Array (); // traverse data for (var I = 0; I
   
    

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.