//新增数据函数
function add(db, newperson) {
var req = db.transaction(["person"], "readwrite").objectStore("person").add({
id: newperson.id,
name: newperson.name,
age: newperson.age,
email: newperson.email
});
req.onsuccess = function(event) {
console.log("数据写入成功");
}
req.onerror = function(event) {
console.log("数据写入失败");
}
}
//读取数据函数
function getdate(db, index) {
var req = db.transaction(["person"], "readonly").objectStore("person").get(index);
req.onsuccess = function(event) {
var result = event.target.result;
if (result) {
console.log("姓名:" + result.name);
console.log("年龄:" + result.age);
console.log("邮箱:" + result.email);
} else {
console.log("未找到数据");
}
req.onerror = function(event) {
console.log("数据读取失败");
}
}
}
js 新增读取函数
最新推荐文章于 2024-08-30 20:29:15 发布