title | slug |
---|---|
Storage.clear() |
Web/API/Storage/clear |
{{APIRef("Web Storage API")}}
{{domxref("Storage")}} 接口的 clear()
方法清除给定 Storage
对象中存储的所有键。
clear()
无。
无 ({{jsxref("undefined")}})。
下面的函数在本地存储里面创建三个数据项,然后使用 clear()
把它们全部移除。
function populateStorage() {
localStorage.setItem("bgcolor", "red");
localStorage.setItem("font", "Helvetica");
localStorage.setItem("image", "miGato.png");
localStorage.clear();
}
Note
有关实际运行的例子,详见 Web Storage 演示。
{{Specifications}}
{{Compat}}