方法返回的就是一个 IDBTransaction 对象。

    1. var trans1 = db.transaction('foo', 'readwrite');
    2. var trans2 = db.transaction('foo', 'readwrite');
    3. var objectStore2 = trans2.objectStore('foo')
    4. var objectStore1 = trans1.objectStore('foo')
    5. objectStore1.put('1', 'key');

    上面代码中,key对应的键值最终是2,而不是。因为事务trans1先于trans2创建,所以首先执行。

    IDBTransaction 对象有以下属性。

    • IDBTransaction.db:返回当前事务所在的数据库对象 IDBDatabase。
    • IDBTransaction.error:返回当前事务的错误。如果事务没有结束,或者事务成功结束,或者被手动终止,该方法返回null
    • IDBTransaction.mode:返回当前事务的模式,默认是readonly(只读),另一个值是。
    • IDBTransaction.onabort:指定abort事件(事务中断)的监听函数。
    • IDBTransaction.oncomplete:指定complete事件(事务成功)的监听函数。
    • IDBTransaction.onerror:指定error事件(事务失败)的监听函数。
    • IDBTransaction.abort():终止当前事务,回滚所有已经进行的变更。