點擊「清除存儲」按鈕後,我有以下html代碼清除網絡存儲數據。onclick永不執行功能
資源管理器(chrome和firefox)在點擊清除存儲按鈕後從未觸發該功能。
的代碼是:
<html>
<head>
<script>
function clear() {
console.log();
localStorage.clear();
refreshContents();
alert("all cache data cleared!");
}
function refreshContents() {
var str = "";
alert("in refresh");
for (var i = 0, len = localStorage.length; i < len; i++) {
var k = localStorage.key(i);
var v = localStorage.getItem(k);
str += "'" + k + "' = '" + v + "'<br />";
}
alert("after for loop");
key.value = "";
value.value = "";
content.innerHTML = str;
}
</script>
</head>
<body>
<div class="content"> <!-- end .content -->
<p>This is the logout page.</p>
<p>All temporary data will be erased after logout.
<p> </p>
<input type="button" onclick="clear();" value="Clear Storage" />
Contents of Local Storage:<br />
<span id="content"></span>
</body>
</html>
有人可以幫助請。 在此先感謝!
嘗試將名稱更改爲'clearStorage' – Tushar