监听 storage
if (window.addEventListener) {
window.addEventListener("storage", onStorageChange);
} else if (window.attachEvent) {
window.attachEvent("onstorage", onStorageChange);
function onStorageChange(e) {}
storage 事件里的 e 是一个 StorageEvent 对象。 有如下属性
AttributeTypeFunctionkeyStringadded, removed, or moddifiedoldValueAnyold value,or null if a new item was addednewValueAnynew value,or null if a new item was removedurl/uriStringpage causing change
db.transaction(function (tx) { tx.executeSql( "SELECT * FROM LOGS", [], function (tx, results) { var len = results.rows.length, i, msg = "<p>查询记录条数: " + len + "</p>"; document.querySelector("#status").innerHTML += msg; for (i = 0; i < len; i++) { alert(results.rows.item(i).log); } }, null ); });
删除数据
db.transaction(function (tx) { tx.executeSql("DELETE FROM LOGS WHERE id=?", [id]); });
更新数据
db.transaction(function (tx) { tx.executeSql("UPDATE LOGS SET log='www.w3cschool.cc' WHERE id=?", [id]); });
是否支持WebSQL
if (window.openDatabase) { // 操作 web SQL } else { alert('当前浏览器不支持 webSQL !!!'); }