1

我在我的 html 表单中插入了这些值。即使在成功插入数据后,它在 chrome 的开发者工具中也不可见。我应该检查一些设置还是我的浏览器有任何缓存问题。我的数据库和表已创建,但我的值没有被插入。我在下面提供我的代码。

$(document).ready(function() {

     var db = openDatabase("todolist", 1.0, "To Do List Database", 100 * 1024);
     db.transaction(function(transaction) {
         transaction.executeSql("CREATE TABLE IF NOT EXISTS list(" + "ID INTEGER PRIMARY KEY ASC," + " name TEXT NOT NULL," + " description TEXT," + " due DATETIME," + " start DATETIME);", []);
     });

     $("#submit").click(function() {
         var name = $("#taskname").val();
         //alert(name);
         var desc = $("#taskdesc").val();
         //alert(desc);
         var due = $("#taskdue").val();
         //alert(due);
         var start = $("#taskstart").val();
         //alert(start);
         db.transaction(function(transaction) {
             var sql = "INSERT INTO list(name,description,due,start )VALUES(?,?,?,?)";
             transaction.executeSql(sql, [name, desc, due, start], function() {

                 alert("Values Inserted")
             }, error);
         });
     });

     function error(transaction, err)

     {
         alert("DB error : " + err.message);
         return false;
     }
 });
4

2 回答 2

0

好的,所以我能够让这些命令在测试数据库上工作,所以我猜你要么有两个问题之一。您的任何一个值(名称、描述、到期、开始)都未定义,或者您需要添加一个“;” 到您的插入命令

var sql = "INSERT INTO list(name,description,due,start )VALUES(?,?,?,?);";

代替

var sql = "INSERT INTO list(name,description,due,start )VALUES(?,?,?,?)";
于 2012-10-10T10:56:48.077 回答
0
var x = {};
x.web = {};
db= null;
x.web.open=function()
{
    //alert("hiiii")
    db= openDatabase("amith",1.0,"To Do List Database",100*1024);
}
x.web.create=function()
{
    var data=db;
    //alert(data)
    data.transaction(function(transaction){
    transaction.executeSql(
    "CREATE TABLE IF NOT EXISTS type("+
    "ID INTEGER PRIMARY KEY ASC,"+
    " name TEXT NOT NULL,"+
    " description TEXT,"+
    " due DATETIME,"+
    " start DATETIME)");
    });

}
x.web.addTodo = function(name,desc,due,start) 
    {
        var data1 = db;
        data1.transaction(function(tx){
        var sql="INSERT INTO     
   type(name,description,due,start)VALUES(?,?,?,?)";
        tx.executeSql(sql,[name,desc,due,start],function(){
        //alert("Values Inserted")
        },error);
        });
    }
 function error (transaction, err) 

    {
        alert ("DB error : " + err.message);
        return false;
    }

function init()
{
    x.web.open();
    x.web.create();
}
 function addTodo() 
{
    //alert("toodod")
    var name = document.getElementById("taskname").value;
    var desc= document.getElementById("taskdesc").value;
    var due= document.getElementById("taskdue").value;
    var start=document.getElementById("taskstart").value
    //alert(name);
    x.web.addTodo(name,desc,due,start);
}
于 2012-10-15T06:19:48.950 回答