检查 HTML5 本地存储中是否存在某个键
htmlweb developmentfront end technology更新于 2024/8/14 23:40:17
getitem(key) 函数接受一个参数的值,并返回与该键关联的值。给定的键存在于与该对象关联的列表中。
if(localStorage.getItem("user")===null) {
//...
但是,如果键不在列表中,则使用以下代码传递 null 值
您也可以按照以下步骤操作 −
if("user" in localStorage){
alert('yes');
} else {
alert('no');
}
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

