标签:web ges img func var javascrip 分享 asc set
1.介绍
2.核心方法
3.openDatabase方法
4.transaction方法
5.executeSql方法
6.举例
7.程序
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 5 <title>html5-dataBase</title> 6 </head> 7 8 9 <body> 10 <script type="text/javascript"> 11 var db = window.openDatabase("mydata", "1.0","数据库描述",20000); 12 //window.openDatabase("数据库名字", "版本","数据库描述",数据库大小); 13 if(db) 14 alert("新建数据库成功!"); 15 16 db.transaction(function(tx) { 17 tx.executeSql("CREATE TABLE test (id int UNIQUE, mytitle TEXT, timestamp REAL)"); 18 }); 19 20 db.transaction(function(tx) { 21 tx.executeSql("INSERT INTO test (mytitle, timestamp) values(?, ?)", ["WEB Database", new Date().getTime()], null, null); 22 }); 23 24 //db.transaction(function(tx) { 25 // tx.executeSql("DROP TABLE qqs"); 26 //}) 27 28 //db.transaction(function(tx) { 29 // tx.executeSql("update test set mytitle=? where mytitle = ‘fsafdsaf‘",[‘xp‘],null,null); 30 //}); 31 32 db.transaction(function(tx) { 33 tx.executeSql("SELECT * FROM test", [], 34 function(tx, result) { 35 for(var i = 0; i < result.rows.length; i++){ 36 document.write(‘<b>‘ + result.rows.item(i)[‘mytitle‘] + ‘</b><br />‘); 37 } 38 }, function(){ 39 alert("error"); 40 }); 41 }); 42 </script> 43 </body> 44 </html>
标签:web ges img func var javascrip 分享 asc set
原文地址:http://www.cnblogs.com/juncaoit/p/7129041.html