<!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>