IDBDatabase: version 屬性
注意:此功能在 Web Workers 中可用。
IDBDatabase 介面的 version 屬性是一個 64 位整數,其中包含連線資料庫的版本。當資料庫首次建立時,此屬性為空字串。
值
一個整數,包含連線資料庫的版本。
示例
js
// Let us open our database
const DBOpenRequest = window.indexedDB.open("toDoList", 4);
// these two event handlers act on the database
// being opened successfully, or not
DBOpenRequest.onerror = (event) => {
note.appendChild(document.createElement("li")).textContent =
"Error loading database.";
};
DBOpenRequest.onsuccess = (event) => {
note.appendChild(document.createElement("li")).textContent =
"Database initialized.";
// store the result of opening the database in the db variable. This is used a lot below
db = DBOpenRequest.result;
// This line will log the version of the connected database, which should be "4"
console.log(db.version);
};
規範
| 規範 |
|---|
| Indexed Database API 3.0 # ref-for-dom-idbdatabase-version① |
瀏覽器相容性
載入中…
另見
- 使用 IndexedDB
- 開始事務:
IDBDatabase - 使用事務:
IDBTransaction - 設定鍵的範圍:
IDBKeyRange - 檢索和修改資料:
IDBObjectStore - 使用遊標:
IDBCursor - 參考示例:待辦事項通知(檢視即時示例)。