local storage にkey valueを保存

<script type="text/javascript">
if(typeof localStorage == 'undefined'){
 document.write("<p>お使いのブラウザではお気に入り機能が使えません。</p>");
} else {
	var storage = localStorage;

	function setlocalStorage(){
		var key = document.getElementById("textkey").value;
		var value = document.getElementById("textdata").value;
		if (key && value){
			storage.setItem(key, value);
		}
		key = "";
		value = "";
		viewStorage();
	}

	function removeStorage(){
		var key = document.getElementById("textkey").value;
		storage.removeItem(key);
		key = "";
		viewStorage();
	}

	function removeallStorage(){
		storage.clear();
		viewStorage();
	}

	function viewStorage() {
		var list = document.getElementById("list")
		while(list.firstChild)list.removeChild(list.firstChild);
		for (var i=0; i < storage.length; i++){
			var _key = storage.key(i);
			var tr = document.createElement("tr");
			var td1 = document.createElement("td");
			var td2 = document.createElement("td");
			list.appendChild(tr);
			tr.appendChild(td1);
			tr.appendChild(td2);
			td1.innerHTML = _key;
			td2.innerHTML = storage.getItem(_key);
		}
	}

	function load(){
		var list = document.getElementById("list")
		while (list.firstChild) list.removeChild(list.firstChild);
		for (var i =0; i < localStorage.length; i++){
			var _key = localStorage.key(i);
			var tr = document.createElement("tr");
			var td1 = document.createElement("td");
			var td2 = document.createElement("td");
			list.appendChild(tr);
			tr.appendChild(td1);
			tr.appendChild(td2);
			td1.innerHTML = _key;
			td2.innerHTML = localStorage.getItem(_key);
		}
	}
}
</script>

<h4>お気に入り銘柄入力フィールド</h4>
<p> code : <input id="textkey" type="text"/> 銘柄名:<input id="textdata" type="text"/></p>
<p align="right"><button id="button" onclick="setlocalStorage()">保存</button>
<button id="button" onclick="removeStorage()">削除</button>
<button id="button" onclick="removeallStorage()">全て削除</button></p>

<h4>入力結果</h4>
<table class="tagForList2">
	<tr>
		<th>コード</th><th>銘柄名</th>
	</tr>
	<tbody id="list">
	</tbody>
</table>