复制代码 代码如下:www.CuoXIn.com
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
</style>
</head>
<body>
<div>
</div>
<script type="text/javascript">
//openDatabase方法打开已经存在的数据库,如果不存在将会创建一个数据库
var db = window.openDatabase("mydatabase", "1.0", "我的数据库描述", 20000);
var d = new Date();
//创建数据表
var sql = "CREATE TABLE mytable (mytitle TEXT, timestamp REAL)";
db.transaction(function (tx) {
tx.executeSql(sql);
});
//往数据表插入数据
db.transaction(function (tx) {
tx.executeSql("INSERT INTO mytable (mytitle, timestamp) values(?, ?)", ["广州大学华软软件学院3", d.toLocaleString()], null, null);
});
//删除数据表
//db.transaction(function (tx) {
// tx.executeSql("DROP TABLE mytable ");
//});
db.transaction(function (tx) {
tx.executeSql("SELECT * FROM mytable", [],
function (tx, result) {
for (var i = 0; i < result.rows.length; i++) {
document.write('<h1>' +
result.rows.item(i)['mytitle'] + " " +
result.rows.item(i)['timestamp'] +
'</h1>');
}
},
function () {
alert("error");
});
});
</script>
</body>
</html>