indexedDB数据库的基本概念:在HTML5中,新增一种被称为“indexedDB”的数据库,该数据库是一种存储在客户端本地的NoSQL数据库。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
window.indexedDB=window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB;
window.IDBTransaction= window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction;
window.IDBKeyrange=window.IDBKeyrange || window.webkitIDBKeyrange ||window.msIDBKeyrange;
window.IDBCursor= window.IDBCursor || window.webkitIDBCursor || window.msIDBCursor; function CreateObjectStore() {
var dbName = "indexedDBtest";
var dbVersion = 3;
var idb;
var dbConnect = indexedDB.open(dbName,dbVersion);
dbConnect.onsuccess = function (e) {
idb = e.target.result;
alert("数据库链接成功");
};
dbConnect.onerorr = function () {
alert("链接数据库失败");
}
dbConnect.onupgradeneeded = function (e) {
idb = e.target.result;
var name = "user";
var optionalParameters = {
keyPath:"userid",
autoIncrement:false
};
var store = idb.createObjectStore(name,optionalParameters);
alert("对象仓库创建成功");
}
}
</script>
</head>
<body>
<input type="button" value="创建仓库" onclick="CreateObjectStore()">
</body>
</html>
显示效果: