码迷,mamicode.com
首页 > 数据库 > 详细

H5中的web dataBase数据库

时间:2017-07-07 00:53:23      阅读:359      评论:0      收藏:0      [点我收藏+]

标签: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>

 

H5中的web dataBase数据库

标签:web   ges   img   func   var   javascrip   分享   asc   set   

原文地址:http://www.cnblogs.com/juncaoit/p/7129041.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!