1 Star 0 Fork 0

yssh / study_jsBomDom

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
08-indexedDB.html 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
yssh 提交于 2022-03-22 10:09 . first commit
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
<script>
var openRequest = window.indexedDB.open("test", 1);
var db;
openRequest.onupgradeneeded = function(event) {
db = event.target.result;
var objectStore = db.createObjectStore('person', { keyPath: 'id' });
// var objectStore;
// if (!db.objectStoreNames.contains('person')) {
// objectStore = db.createObjectStore('person', {
// autoIncrement: true
// });
// }
// objectStore.createIndex('name', 'name', {
// unique: false
// });
// objectStore.createIndex('email', 'email', {
// unique: true
// });
console.log("Upgrading...");
}
openRequest.onsuccess = function(e) {
console.log('Success!');
db = openRequest.result;
}
// openRequest.onerror = function(e) {
// console.log('Error');
// console.log(e);
// }
function add() {
var request = db.transaction(['person'], 'readwrite')
.objectStore('person')
.add({
id: 1,
name: '张三',
age: 24,
email: 'zhangsan@example.com'
});
request.onsuccess = function(event) {
console.log('数据写入成功');
};
request.onerror = function(event) {
console.log('数据写入失败');
}
}
// add();
setTimeout(()=>{
add();
},5000)
</script>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/twoflowers/study-js-bom-dom.git
git@gitee.com:twoflowers/study-js-bom-dom.git
twoflowers
study-js-bom-dom
study_jsBomDom
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891