值
包含已連線資料庫名稱的字串。
示例
本示例展示了開啟資料庫連線、將生成的 IDBDatabase 物件儲存在 db 變數中,然後記錄 name 屬性。有關完整示例,請參閱我們的 待辦事項通知 應用(即時檢視示例)。
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 name of the database, which should be "toDoList"
console.log(db.name);
};
規範
| 規範 |
|---|
| Indexed Database API 3.0 # ref-for-dom-idbdatabase-name① |
瀏覽器相容性
載入中…
另見
- 使用 IndexedDB
- 開始事務:
IDBDatabase - 使用事務:
IDBTransaction - 設定鍵的範圍:
IDBKeyRange - 檢索和修改資料:
IDBObjectStore - 使用遊標:
IDBCursor - 參考示例:待辦事項通知(檢視即時示例)。