码迷,mamicode.com
首页 > 数据库 > 详细

数据库indexDB

时间:2016-07-02 13:16:22      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:

 1,链接数据库

      

技术分享
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script>
            
            window.indexedDB = window.indexedDB ||
                               window.mozIndexedDB ||
                               window.webkitIndexedDB ||
                               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 connectDatabase(){
                  var dbName = "indexedDBtest";
                  var dbVersion = 1;
                  var idb;
                  var dbConnect = indexedDB.open(dbName,dbVersion);   //打开数据库
                  dbConnect.onsuccess = function(e){           //是否链接成功,链接成功之后,返回信息
                      idb = e.target.result;
                      alert("数据库链接成功")
                  }
                  dbConnect.onerror = function(e){
                       alert("数据库链接失败")
                      
                  }
                
            }
        </script>
    </head>
    <body>
        <input type="button" value="链接数据库" onclick="connectDatabase()">
    </body>   
     
</html>
View Code

 2,数据库版本更新

  

技术分享
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script>
            
            window.indexedDB = window.indexedDB ||
                               window.mozIndexedDB ||
                               window.webkitIndexedDB ||
                               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 versionUpdata(){
                  var dbName = "indexedDBtest";
                  var dbVersion = 2;
                  var idb;
                  var dbConnect = indexedDB.open(dbName,dbVersion);
                  dbConnect.onsuccess = function(e){
                         idb = e.target.result;
                         alert("数据库链接成功");                      
                  }
                   dbConnect.error = function(){
                            alert("数据库更新失败")                   
                   }
                    dbConnect.onupgradeneeded = function(e){
                          idb = e.target.result;
                          var tx = e.target.transaction;
                          var oldVersion = e.oldVersion;
                          var newVersion = e.newVersion;
                          alert("数据库更新成功"+oldVersion+"--"+newVersion);
                        
                    }
                
            }
        </script>
    </head>
    <body>
        <input type="button" value="链接数据库" onclick="versionUpdata()">
    </body>   
     
</html>
View Code

 

数据库indexDB

标签:

原文地址:http://www.cnblogs.com/147258llj/p/5635142.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!