WebSQL - Phonegap

时间:2014-04-16 15:10:32

标签: javascript android html cordova web-sql

我想使用Phonegap制作应用,但我对Web SQL编码有疑问。 该应用程序非常简单:button1选择当前时间并设置为value1,然后button1再次选择当前时间并设置为value2;一个用于标识活动的字段,在填写完所有字段后,再次按钮1打开一个对话框到OBS,然后打开一个包含所有活动的新页面:

// JavaScript Documentvar db;
var dbCreated = false;

/*var scroll = new iScroll('wrapper', {
 vScrollbar : false,
 hScrollbar : false,
 hScroll : false
}); */
document.addEventListener("deviceready", onDeviceReady, false);

var ativ = document.getElementById("ativ").value;
var hi = document.getElementById("hi").value;
var hf = document.getElementById("hf").value;
var obs = document.getElementById("obs").value;

function onDeviceReady() {

    db = openDatabase("RegistrationDB", "1.0", "Registration", 1024 * 1024);
    if (dbCreated) {
    } else {
        db.transaction(populateDB, transaction_error, populateDB_success);
    }
}

function populateDB(tx) {
    tx.executeSql('DROP TABLE IF EXISTS RegistrationDB');
    var sql = "CREATE TABLE IF NOT EXISTS RegistrationDB ( " + " atividade, " + " horaInicial, " + " horaFinal, " + " observacao)";
    tx.executeSql(sql);
    tx.executeSql("INSERT INTO RegistrationDB (atividade, horaInicial, horaFinal, observacao) VALUES ('" + ativ + "','" + hi + "' , " + hf + ", '" + obs + "')");

}

function transaction_error(tx, error) {
    alert("Database Error: " + error);
}

function populateDB_success() {
    dbCreated = true;

    // where you want to move
    alert("Successfully inserted");
    window.location="tela2.html";
}// JavaScript Document

0 个答案:

没有答案