HTML5 Localstorage JS

Source: Internet
Author: User
Tags sessionstorage

/* HTML5 sessionstorage *///Add Data function Sssetval (key, Val) {if (window.sessionstorage) {//Detect if user enters key if (key== ' | | | val== ') ') {return 0;} Sessionstorage.setitem (key,val); alert (' Data: ' +key+ ', ' +val+ ' add success '); return 1;} Else{alert (' Local storage not supported '); return 0;}} Queries the specified data function ssgetval (key) {//detects if the user entered the key if (key== ') {return 0;} if (window.sessionstorage) {return Sessionstorage.getitem (key);} Else{return 0;}} Modify the Set data function Sschgval (key, Val) {if (window.sessionstorage) {///detect if the user entered the key if (key== ' | | val== ') {return 0;} Sessionstorage.setitem (key,val); alert (' Data: ' +key+ ', ' +val+ ' modified successfully '); return 1;} Else{return 0;}} Deletes the specified data function ssdelval (key) {//detects if the user entered the key if (key== ') {return 0;} if (window.sessionstorage) {Sessionstorage.removeitem (key); return 1;} Else{return 0;}} Traverse all function Ssgetall () {if (window.sessionstorage) {//detect if there is data if (sessionstorage.length==0) {return 0;} var arrkey = new Array ()//Traverse data for (Var i=0;i<sessionstorage.length;i++) {Arrkey[i] = Localstorage.key (i);} return Arrkey;} Else{return 0;}} Number of total bars function Ssgetallcount () {if(Window.sessionstorage) {//Detect if there is data return Sessionstorage.length}else{alert (' Local storage not supported '); return 0;}} Delete all function Ssdelall () {if (window.sessionstorage) {//detect if there is data if (sessionstorage.length==0) {return 0;} Loop Delete//for (var i=0;i<sessionstorage.length;i++) {//sessionstorage.removeitem (Sessionstorage.key (i));/} Sessionstorage.clear (); if (sessionstorage.length==0) {alert (' success '); return 1;} else return 0;} Else{return 0;}}


/* HTML5 localstorage *///Add Data function Lssetval (key, Val) {if (window.localstorage) {///detect if user enters key if (key== ' | | val== ') { return 0;} Localstorage.setitem (Key, Val); Showmodel (' Add success '); return 1;} Else{return 0;}} Queries the specified data function lsgetval (key) {//detects if the user 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 Set data function Lschgval (key, Val) {if (window.localstorage) {///detect if the user entered the key if (key== ' | | val== ') {return 0;} Localstorage.setitem (Key,val); return 1;} Else{return 0;}} Deletes the specified data function lsdelval (key) {//detects if the user entered the key if (key== ') {return 0;} if (window.localstorage) {Localstorage.removeitem (key); return 1;} Else{return 0;}} Traverse all function Lsgetall () {if (window.localstorage) {//detect if there is data if (localstorage.length==0) {//alert (' no items in the current shopping cart, go to add it! ') ); return 0;} var arrkey = new Array ();//Traverse data for (Var i=0;i<localstorage.length;i++) {Arrkey[i] = Localstorage.getitem ( Localstorage.key (i));} return Arrkey;} Else{return 0;}} Number of total bars function Lsgetallcount () {if (window.localstorage) {//detects if there is data return Localstorage.length}else{return 0;}} Remove all function Lsdelall () {if (window.localstorage) {//detect if there is data if (localstorage.length==0) {//alert (' No data in current Localstroge '); return 0;} Loop Delete//for (var i=0;i<localstorage.length;i++) {//localstorage.removeitem (Localstorage.key (i));/} Localstorage.clear (); if (localstorage.length==0) {//alert (' data cleanup succeeded '); return 1;} else return 0;} Else{alert (' Local storage not supported '); return 0;}}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HTML5 Localstorage JS

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.