使用apache-cordova开发HTML5应用,操作数据库参考如下:
<!DOCTYPE html> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <html> <head> <meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,maximum-scale=1.0,initial-scale=1.0" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 --> <title>Cordova Mobile Spec</title> <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8"> <script type="text/javascript" charset="utf-8" src="../cordova.js"></script> <script type="text/javascript" charset="utf-8"> var deviceReady = false; //------------------------------------------------------------------------- // HTML5 Database //------------------------------------------------------------------------- var db; var callDatabase = function() { db = openDatabase("mydb", "1.0", "Apache Cordova Demo", 20000); if (db === null) { databaseOutput("Database could not be opened."); return; } databaseOutput("Database opened."); db.transaction(function (tx) { tx.executeSql('DROP TABLE IF EXISTS DEMO'); tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)', [], function(tx,results) { console.log("Created table"); }, function(tx,err) { alert("Error creating table: "+err.message); }); tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")', [], function(tx,results) { console.log("Insert row1 success"); }, function(tx,err) { alert("Error adding 1st row: "+err.message); }); tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")', [], function(tx,results) { console.log("Insert row2 success"); }, function(tx,err) { alert("Error adding 2nd row: "+err.message); }); databaseOutput("Data written to DEMO table."); console.log("Data written to DEMO table."); tx.executeSql('SELECT * FROM DEMO', [], function (tx, results) { var len = results.rows.length; var text = "DEMO table: " + len + " rows found.<br>"; text = text + "<table border='1'><tr><td>Row</td><td>Data</td></tr>"; for (var i=0; i<len; i++){ text = text + "<tr><td>" + i + "</td><td>" + results.rows.item(i).id + ", " + results.rows.item(i).data + "</td></tr>"; } text = text + "</table>"; databaseOutput(text); }, function(tx, err) { alert("Error processing SELECT * SQL: "+err.message); }); tx.executeSql('SELECT ID FROM DEMO', [], function (tx, results) { var len = results.rows.length; var text = "DEMO table: " + len + " rows found.<br>"; text = text + "<table border='1'><tr><td>Row</td><td>Data</td></tr>"; for (var i=0; i<len; i++){ text = text + "<tr><td>" + i + "</td><td>" + results.rows.item(i).id + "</td></tr>"; } text = text + "</table>"; databaseOutput(text); }, function(tx, err) { alert("Error processing SELECT ID SQL: "+err.message); }); }, function(err) { console.log("Transaction failed: " + err.message); }); }; var readDatabase = function() { if (!db) { db = openDatabase("mydb", "1.0", "Apache Cordova Demo", 20000); if (db === null) { databaseOutput("Database could not be opened."); return; } } db.transaction(function (tx) { tx.executeSql('SELECT * FROM DEMO WHERE id=2', [], function (tx, results) { var len = results.rows.length; var text = "DEMO table: " + len + " rows found.<br>"; text = text + "<table border='1'><tr><td>Row</td><td>Data</td></tr>"; for (var i=0; i<len; i++){ text = text + "<tr><td>" + i + "</td><td>" + results.rows.item(i).id + ", " + results.rows.item(i).data + "</td></tr>"; } text = text + "</table>"; databaseOutput(text); }, function(tx, err) { alert("Error processing SELECT * WHERE id=2 SQL: "+err.message); }); }); } var databaseOutput = function(s) { var el = document.getElementById("database_results"); el.innerHTML = el.innerHTML + s + "<br>"; }; /** * Function called when page has finished loading. */ function init() { document.addEventListener("deviceready", function() { deviceReady = true; console.log("Device="+device.platform+" "+device.version); }, false); window.setTimeout(function() { if (!deviceReady) { alert("Error: Apache Cordova did not initialize. Demo will not run correctly."); } },1000); } </script> </head> <body onload="init();" id="stage" class="theme"> <h1>HTML5 Database</h1> <div id="info"> <b>Results:</b><br> <span id="database_results"></span> </div> <h2>Action</h2> <div class="btn large" onclick="callDatabase();">Create, Add, Read Database</div> <div class="btn large" onclick="readDatabase();">Read Database</div> <h2> </h2><div class="backBtn" onclick="backHome();">Back</div> </body> </html>
相关推荐
在“cordova-plugin-wechat-master”目录下,我们可以看到“cordova-plugin-wechat-develop”文件,这很可能包含了插件的源代码和配置文件。安装插件的命令通常是`cordova plugin add cordova-plugin-wechat-develop...
cordova-plugin-app-update App updater for Cordova/PhoneGap Demo Try it yourself: Just clone and install this demo. cordova-plugin-app-update-DEMO :tada: 如果喜欢它,请别忘了给我一颗鼓励的星 Support ...
Cordova-plugin-finger-print是一款专为Cordova框架设计的插件,主要用于在Android平台上实现指纹识别功能。Cordova是一个流行的开源框架,它允许开发者使用HTML、CSS和JavaScript来构建原生移动应用程序。通过将...
热更新时,我们执行命令 npm install -g cordova-hot-code-push-cli安装插件,但运行cordova-hcp server会报错,如:Could not create tunnel: { Error: ngrok is not yet ready to start tunnels...,这时我们找到...
cordova-plugin-media-capture, Apache Cordova插件媒体捕获镜像 标题说明媒体捕获捕获音频,视频和图像。AppVeyor Travis CI cordova-plugin-media-capture这里插件提供对设备。图像和视频捕获功能的音频访问。警告...
实实在在经过ant编译的cordova-2.9.1.jar 而不是有些人坑蒙拐骗的rar文件
cordova plugin add cordova-plugin-baidumaplocation --variable ANDROID_KEY="" --variable IOS_KEY="" //此处的API_KEY_XX来自于第一步,直接替换,也可以最后跟 --save 参数,将插件信息保存到config....
Cordova-plugin-fingerprint-aio,作为Cordova框架中的一个核心插件,专为移动应用提供了一种高效且安全的身份验证解决方案。该插件是基于Android的Fingerprint API和iOS的LocalAuthentication框架,实现了指纹识别...
cordova-screenshot cordova截屏插件 document.addEventListener("deviceready", init, false); function init() { document.querySelector("#share").addEventListener("touchend", function() { navigator....
启动cordova-hcp server报错 Could not create tunnel: { Error: ngrok is not yet ready to start tunnels 时,将路径 下的cordova-hot-code-push-cli文件下用下载的文件替换就可以了
本文将详细介绍如何借助 `cordova-plugin-wechat` 和 `cordova-plugin-qqsdk` 插件实现在 Ionic 应用中实现微信和 QQ 的分享功能。 1. **申请 AppID** 在使用微信和 QQ 分享功能之前,你需要在相应的开放平台上...
总结,`cordova-plugin-updateapp`是Cordova开发中不可或缺的工具之一,它为App的版本管理和更新提供了便捷高效的解决方案,极大地降低了开发者的维护成本,提升了用户体验。通过深入了解和熟练使用,开发者可以更好...
7. **开发流程**:开发过程中,首先需要安装Cordova和Ionic,然后创建项目,接着添加目标平台(如Android、iOS),安装`cordova-plugin-baidumaplocation`插件,最后在代码中调用插件API实现所需功能。调试时,可以...
7. **开发流程**:使用 `cordova-ios-3.7` 开发应用通常包括以下步骤:设置开发环境(安装 Xcode 和 Cordova),创建新项目,添加 iOS 平台,编写前端代码,安装和配置所需插件,最后进行编译和测试。 8. **调试...
`cordova-uglify`就是这样一个专门为前端开源库`Cordova`设计的工具,用于对应用的JavaScript和CSS进行压缩和混淆,以实现这一目的。 `Cordova`是一个开源的移动应用开发框架,它允许开发者使用Web技术(HTML、CSS...
总之,`cordova-plugin-videoRecorder`为Cordova应用提供了便捷的视频录制功能,简化了跨平台开发的复杂性。通过合理利用这个插件,开发者可以快速地在自己的应用中集成视频拍摄特性,满足用户的多媒体交互需求。
【cordova-plugin-downloadmanagerpro】是一款专为安卓移动开发设计的Cordova插件,它提供了强大的下载管理功能,能够在设备的通知栏中实时展示下载进度,从而为用户带来更加直观的下载体验。这款插件是Cordova生态...
最新版本的phonegap-2.9.1是没有cordova-2.9.1.jar的,这里打包好给大家。
cordova-plugin-firebase-analytics, 用于Firebase分析的Cordova插件 cordova-plugin-firebase-analytics Firebase分析插件的Cordova插件。安装cordova plugin add cordova-plugin-firebase-analyti
Most mobile operating systems are multitasking capable, but most apps dont need to run while in background and not present for the user. Therefore they pause the app in background mode and resume the ...