HTML5 data Store---Use the clear () method to purge all data of Localstorage save objects

Source: Internet
Author: User

<!doctype html>
<meta charset= "Utf-8" >
<title> empty all data of localstorage </title>

<body>
<fieldset>
<input type= "button" id= "Btnadd" onclick= "Add_click ()" value= "Add Data" >
<input type= "button" id= "Btndel" onclick= "Del_click ()" value= "purge Data" >
<p id= "Pstauts" ></p>
</fieldset>
</body>
<script type= "Text/javascript" >
function $ (ID) {
return document.getElementById (ID);
}
var intnum = 0;
Saving Data functions
function Add_click () {
for (var IntI = 0;inti <= 5;inti++) {
var strkeyname = "Strkeyname" +inti;
var strkeyvalue = "strKeyValue" +inti;
Localstorage.setitem (Strkeyname,strkeyvalue);
intnum++;
}
$ ("Pstauts"). Style.display = "block";
$ ("Pstauts"). InnerHTML = "Saved success <br>" +intnum+ "<br> Record"
}
Emptying data functions
function Del_click () {
Localstorage.clear ();
$ ("Pstauts"). Style.display = "block";
$ ("Pstauts"). InnerHTML = "All data has been cleared"
}
/*
Code resolution:
When the user clicks on "Add Data", the loop is used to save 6 data records in the order of execution
Its key name "Strkeyname" is connected to the variable inti, whose value name "strKeyValue" is also connected to the Inti, the data
Saved by the Localstorage object, you can click the right mouse button in the browser chrome and select the "Review element" option.
Click the resources option to view the data saved by Localstorage
When the user "click to clear Data" will empty the Localstorage object to save the data record
*/

</script>

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.