1 Star 0 Fork 0

lirongfei123/locStorage

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
userData.html 1.86 KB
一键复制 编辑 原始数据 按行查看 历史
李荣平 提交于 2015-11-10 11:33 . init
<!doctype html><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=10" />
<title>标题</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
</head>
<script type="text/javascript">
var UserData = {
userData: null,
name: location.hostname,
//this.name = "css88.com";
init: function() {
if (!UserData.userData) {
try {
UserData.userData = document.createElement('INPUT');
UserData.userData.type = "hidden";
UserData.userData.style.display = "none";
UserData.userData.addBehavior("#default#userData");
document.body.appendChild(UserData.userData);
var expires = new Date();
expires.setDate(expires.getDate() + 365);
UserData.userData.expires = expires.toUTCString();
} catch (e) {
return false;
}
}
return true;
},
setItem: function(key, value) {
if (UserData.init()) {
UserData.userData.load(UserData.name);
UserData.userData.setAttribute(key, value);
UserData.userData.save(UserData.name);
}
},
getItem: function(key) {
if (UserData.init()) {
UserData.userData.load(UserData.name);
return UserData.userData.getAttribute(key)
}
},
remove: function(key) {
if (UserData.init()) {
UserData.userData.load(UserData.name);
UserData.userData.removeAttribute(key);
UserData.userData.save(UserData.name);
}
}
};
</script>
<body>
<script type="text/javascript">
UserData.setItem("dd","sdfsd");
alert(UserData.getItem("dd"));
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/lirongfei/locStorage.git
git@gitee.com:lirongfei/locStorage.git
lirongfei
locStorage
locStorage
master

搜索帮助