[[pagelist(html5practice/*)]]
== html ==
{{{
html favorite list test
}}}
== javascript ==
{{{
function doSetItem(aForm) {
localStorage.setItem( document.formInput.elements['textInput'].value, "false");
document.formInput.elements['textInput'].value = "";
doShowAll();
}
function doRemoveItem(itemName) {
localStorage.setItem(itemName, "false");
doShowAll();
}
function doSetFavorite(eTD){
console.log(eTD.innerHTML);
localStorage.removeItem(eTD.innerHTML);
localStorage.setItem(eTD.innerHTML, "true");
doShowAll();
}
function doRemoveFavorite(eTD){
console.log(eTD.innerHTML);
localStorage.removeItem(eTD.innerHTML);
localStorage.setItem(eTD.innerHTML, "false");
doShowAll();
}
function doShowFavorite(){
console.log("do show all");
var key = "";
var pairs = "Name | Value |
\n";
var i=0;
for (i=0; i<=localStorage.length-1; i++) {
key = localStorage.key(i);
value = localStorage.getItem(key);
if( value == "true" )
pairs += ""+key+" | \n"+value+" |
\n";
}
if (localStorage.length == 0){
pairs += "empty | \nempty |
\n";
}
pairs += "
";
document.getElementById('favoriteList').innerHTML = pairs;
console.log("end do show all");
}
function doShowNFavorite(){
var key = "";
var pairs = "Name | Value |
\n";
var i=0;
for (i=0; i<=localStorage.length-1; i++) {
key = localStorage.key(i);
value = localStorage.getItem(key);
if( value == "false" )
pairs += ""+key+" | \n"+value+" |
\n";
}
if (localStorage.length == 0){
pairs += "empty | \nempty |
\n";
}
pairs += "
";
document.getElementById('allList').innerHTML = pairs;
}
function doShowAll() {
doShowNFavorite();
doShowFavorite();
}
function doClearAll(){
localStorage.clear();
doShowAll();
}
}}}