自测通过,如下代码:
var db = openDatabase('webdb', '1.0', 'HTML5 DB', 5 * 1024 * 1024);
var msg;
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS TAGS (id unique, tag)');
tx.executeSql('INSERT INTO TAGS (id, tag) VALUES (1, "liaojianguo")');
tx.executeSql('INSERT INTO TAGS (id, tag) VALUES (2, "love html5")');
msg = '
tag message created and row inserted.
';document.querySelector('#divId').innerHTML = msg;
});
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM TAGS', [], function (tx, results) {
var len = results.rows.length, i;
msg = "
Found rows: " + len + "
";document.querySelector('#divId').innerHTML += msg;
for (i = 0; i < len; i++){
msg = "
" + results.rows.item(i).tag + "
";document.querySelector('#divId').innerHTML += msg;
}
}, null);
});