瀏覽器內(nèi)置數(shù)據(jù)庫(kù)
// 數(shù)據(jù)庫(kù)demo
var testDB = window.indexedDB.open("testDB", 4);
var db;
testDB.onsuccess = function(event){
console.log("成功打開(kāi)DB");
db = event.target.result;
//創(chuàng)建表
var objectStore = database.createObjectStore("students", { keyPath: rollNo });
//創(chuàng)建事物
var tran = db.transaction(["students"],"readwrite");
//獲取表
var objectStore = tran.objectStore("students");
//往表添加數(shù)據(jù)
objectStore.add({rollNo: '1', name: 'mxp'});
//根據(jù)主鍵獲取數(shù)據(jù)
var mxp = objectStore.get('1');
//獲取成功回調(diào)
mxp.onsuccess = function(event){
console.log("Name : "+mxp.result.name);
};
}