html5 sqlite(Web SQL)
来源:互联网 发布:上市公司高管薪酬数据 编辑:程序博客网 时间:2024/05/16 05:25
1)查看Web SQL 数据库
a) Chrome F12
b) Safari Ctrl+Alt+I
代码
<!DOCTYPE html><html><head> <meta name="viewport" content="width=device-width" /> <title>sqlite</title> <script type="text/javascript"> var db; function Onload() { db = CreateOrOpenDB('MyTestDB'); } function CreateOrOpenDB(dbname) {//创建或打开一个本地的数据库对象 var db = openDatabase(dbname, '1.0', '', 2 * 1024 * 1024); return db; } function CreateTable() {//创建表 db.transaction(function (context) { context.executeSql('CREATE TABLE IF NOT EXISTS Student (id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT,address TEXT)'); }, function (error) { console.log('创建表失败:[' + error.message + ']'); }, function () { console.log('创建表成功'); }); } function InsertData() {//插入数据 db.transaction(function (context) { context.executeSql('INSERT INTO Student (name,address) VALUES ("张三","浙江")'); context.executeSql('INSERT INTO Student (name,address) VALUES ("李四","江苏")'); context.executeSql('INSERT INTO Student (name,address) VALUES ("王五","上海")'); }, function (error) { console.log('插入数据失败:[' + error.message + ']'); }, function () { console.log('插入数据成功'); }); } function UpdateData() {//更新数据 db.transaction(function (context) { context.executeSql('UPDATE Student SET address="海南" WHERE id=1'); }, function (error) { console.log('更新数据失败:[' + error.message + ']'); }, function () { console.log('更新数据成功'); }); } function DeleteData() {//删除数据 db.transaction(function (context) { context.executeSql('DELETE FROM Student WHERE id=1'); }, function (error) { console.log('删除数据失败:[' + error.message + ']'); }, function () { console.log('删除数据成功'); }); } function SelectData() {//查询数据 db.transaction(function (context) { context.executeSql('SELECT * FROM Student', [], function (context, results) { var items = results.rows; for (i = 0; i < items.length; i++) { var item = items.item(i); alert('{id:"' + item.id + '",name:"' + item.name + '",address:"' + item.address + '"}'); } }); }, function (error) { console.log('查询数据失败:[' + error.message + ']'); }, function () { console.log('查询数据成功'); }); } function DropTable() {//删除表 db.transaction(function (context) { context.executeSql('DROP TABLE IF EXISTS Student'); }, function (error) { console.log('删除表失败:[' + error.message + ']'); }, function () { console.log('删除表成功'); }); } </script></head><body onload="Onload();"> <div> <table style=" width:100%"> <tr><td><input type="button" value="创建表" onclick="CreateTable();" style=" width:100%; height:100px;"></td></tr> <tr><td><input type="button" value="插入数据" onclick="InsertData();" style=" width:100%; height: 100px;"></td></tr> <tr><td><input type="button" value="更新数据" onclick="UpdateData();" style=" width:100%; height: 100px;"></td></tr> <tr><td><input type="button" value="删除数据" onclick="DeleteData();" style=" width:100%; height: 100px;"></td></tr> <tr><td><input type="button" value="查询数据" onclick="SelectData();" style=" width:100%; height: 100px;"></td></tr> <tr><td><input type="button" value="删除表" onclick="DropTable();" style=" width:100%; height: 100px;"></td></tr> </table> </div></body></html>
0 0
- html5 sqlite(Web SQL)
- HTML5 Web SQL
- [html5]Web SQL
- HTML5 Web SQL
- HTML5 Web SQL
- HTML5 Web SQL 数据库
- HTML5のWeb SQL
- HTML5 Web SQL 数据库
- HTML5 Web SQL 数据库!
- html5 之web SQL
- HTML5 Web SQL 数据库
- HTML5 Web SQL 数据库
- HTML5 Web SQL
- HTML5 Web SQL Database 数据库
- HTML5 web存储—web SQL
- Web SQL Database 之 SQLite语法
- html5 本地数据库-Web SQL Database
- HTML5开发 Web SQL Database 本地数据库
- 淘宝一面 关于JavaScript中的事件代理(例子:ul中无数的li上添加点击事件)
- 很全面的登陆注册界面实现,包括页面显示和后台数据库交互(写了我一下午)
- 虚拟机安装vmware tools
- HDU 3682 To Be an Dream Architect (STL去重--思路题目)
- 一步一步解析java集合框架HashMap源码(1)
- html5 sqlite(Web SQL)
- HDU 4651 数学 五边形数定理
- hdu5790 Prefix(Trie树+主席树)
- How to give custom labels to x axis of chart control?
- ceph存储 ceph源码调试中admin_socket接口
- 华为 删数
- UNIX环境高级编程——学习路线图
- 通过cmd后去keystore的SHA1指纹
- Dex文件格式详解