window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB; window.IDBTransaction window.webkitIDBTransaction || window.msIDBTransaction; window.IDBKeyRange window.webkitIDBKeyRange || window.msIDBKeyRange; function VersionUpdate () { ; ; var idb; indexedDB.open(dbName,dbVersion); dbConnect.onsuccess=function (e) { idb=e.target.result; alert() } dbConnect.onerror=function(e){ alert(); } dbConnect.onupgradeneeded=function(e){ idb=e.target.result; e.target.transaction; e.oldVersion; e.newVersion; alert(newVersion); } }
View Code 创建对象仓库对于创建对象仓库与索引的操作,我们只能在版本更新事务内部进行,因为在indexedDB API中不允许数据库中的对象仓库在同一个版本中发生改变。
新建createStorge.html,代码如下:
window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB; window.IDBTransaction window.webkitIDBTransaction || window.msIDBTransaction; window.IDBKeyRange window.webkitIDBKeyRange || window.msIDBKeyRange; function CreateStorge () { ; ; var idb; indexedDB.open(dbName,dbVersion); dbConnect.onsuccess=function (e) { idb=e.target.result; alert() } dbConnect.onerror=function(e){ alert(); } dbConnect.onupgradeneeded=function(e){ idb=e.target.result; ; }; idb.createObjectStore(name,optionParams); alert(); } }
View Code