值
包含已连接数据库名称的字符串。
示例
本示例展示了打开数据库连接、将生成的 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 - 参考示例:待办事项通知(查看实时示例)。