html5支持web sql database这能做成本地化交互的一种操作,还是时间没那么多 只放出代码给大家参考 [html] <!doctype html> <html> <head> <meta charset="utf-8"> <title>Web SQL</title> </head> <body> <script> var db=false; var dbo={ createDatabase:function(dbName,ver,descripe,size){ db=window.openDatabase(dbName,ver,descripe,size); }, executeSQL:function(sql){ db.transaction(function(fx){ fx.executeSql(sql); }); }, query:function(sql,recordset){ db.transaction(function(fx){ fx.executeSql(sql,[],function(a,result){recordset(result);},function(){recordset("error");} ); }); } }; dbo.createDatabase("testDB","1.0","测试数据库",2000); dbo.executeSQL("create table xxx (id int primary key, user char(8) null)"); dbo.executeSQL("insert into xxx (id , user) values(1, 'aaaa');"); dbo.executeSQL("insert into xxx (id , user) values(2, 'bbbb');"); dbo.executeSQL("insert into xxx (id , user) values(3, 'cccc');"); dbo.executeSQL("insert into xxx (id , user) values(4, '测试中文');"); dbo.query("select * from xxx",function(myrecord){ for(var i=0;i<myrecord.rows.length;i++){ console.log( myrecord.rows.item(i)["id"]+"-"+myrecord.rows.item(i)["user"] ); } }); dbo.query("select max(id) as maxId from xxx",function(maxId){ console.log( "最大ID:"+maxId.rows.item(0)["maxId"] ); }); </script> </body> </html> [/html]

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部