Skip to content

Latest commit

 

History

History
51 lines (32 loc) · 920 Bytes

File metadata and controls

51 lines (32 loc) · 920 Bytes
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}}

相关链接

使用 Web Storage API