javascript - jQuery 第 67 行说 "TypeError: ' undefined' 不是一个函数。”

标签 javascript jquery cordova steroids

var dbShell;
function doLog(s){
    /*

    setTimeout(function(){

        console.log(s);

    }, 3000);

    */
}

function dbErrorHandler(err){
    alert("DB Error: "+err.message + "\nCode="+err.code);
}

function phoneReady(){
    doLog("phoneReady");
    //First, open our db
    dbShell = window.openDatabase("SimpleNotes", 2, "SimpleNotes", 1000000);
    doLog("db was opened");
    //run transaction to create initial tables
    dbShell.transaction(setupTable,dbErrorHandler,getEntries);
    doLog("ran setup");
}
//I just create our initial table - all one of em
function setupTable(tx){
    doLog("before execute sql...");
    tx.executeSql("CREATE TABLE IF NOT EXISTS notes(id INTEGER PRIMARY KEY,title,body,updated)");
    doLog("after execute sql...");
}   
//I handle getting entries from the db
function getEntries() {
    //doLog("get entries");
    dbShell.transaction(function(tx) {
        tx.executeSql("select id, title, body, updated from notes order by updated desc",[],renderEntries,dbErrorHandler);
    }, dbErrorHandler);
}

function renderEntries(tx,results){
    doLog("render entries");
    if (results.rows.length == 0) {
        $("#mainContent").html("<p>You currently do not have any notes.</p>");
    } else {
       var s = "";
       for(var i=0; i<results.rows.length; i++) {
         s += "<li><a href='edit.html?id="+results.rows.item(i).id + "'>" + results.rows.item(i).title + "</a></li>";   
       }
       $("#noteTitleList").html(s);
       $("#noteTitleList").listview("refresh");
    }
}

function saveNote(note, cb) {
    //Sometimes you may want to jot down something quickly....
    if(note.title == "") note.title = "[No Title]";
    dbShell.transaction(function(tx) {
        if(note.id == "") tx.executeSql("insert into notes(title,body,updated) values(?,?,?)",[note.title,note.body, new Date()]);
        else tx.executeSql("update notes set title=?, body=?, updated=? where id=?",[note.title,note.body, new Date(), note.id]);
    }, dbErrorHandler,cb);
}

function init(){
    document.addEventListener("deviceready", phoneReady, false);
    //handle form submission of a new/old note
    $("#editNoteForm").live("submit",function(e) {
        var data = {title:$("#noteTitle").val(), 
                    body:$("#noteBody").val(),
                    id:$("#noteId").val()
        };
        saveNote(data,function() {
            $.mobile.changePage("index.html",{reverse:true});
        });
        e.preventDefault();
    });

    //will run after initial show - handles regetting the list
    $("#homePage").live("pageshow", function() {
        getEntries(); 
    });

    //edit page logic needs to know to get old record (possible)
    $("#editPage").live("pageshow", function() {
    var loc = $(this).data("url");
        if(loc.indexOf("?") >= 0) {
            var qs = loc.substr(loc.indexOf("?")+1,loc.length);
            var noteId = qs.split("=")[1];
            //load the values
            $("#editFormSubmitButton").attr("disabled","disabled"); 
            dbShell.transaction(
                function(tx) {
                    tx.executeSql("select id,title,body from notes where id=?",[noteId],function(tx,results) {
                        $("#noteId").val(results.rows.item(0).id);
                        $("#noteTitle").val(results.rows.item(0).title);
                        $("#noteBody").val(results.rows.item(0).body);
                        $("#editFormSubmitButton").removeAttr("disabled");   
                    });
                }, dbErrorHandler);

        } else {
         $("#editFormSubmitButton").removeAttr("disabled");   
        }
    });
}

这是我的代码,太长了,是吧?

好吧,无论如何,我大部分都是从 here 得到的。 ,但是我在第 67 行收到错误消息“TypeError: 'undefined' is not a function.”。

我正在使用 Steroids(类似phonegap)并在 iPhone 模拟器上测试 dis。我确信它使用一些 Cordova 来进行数据库工作。

感谢您的帮助:-)

最佳答案

从 jQuery 1.7 开始,第 67 行的 .live() 方法已被弃用。官方文档建议您使用 .on() 或 .delegate() 请参阅:jQuery .live()

关于javascript - jQuery 第 67 行说 "TypeError: ' undefined' 不是一个函数。”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19758497/

相关文章:

javascript - 使用 Node js 进行 Angular http 路由

javascript - 如何读取 php cookie 值中的 jquery cookie 值?

jquery - jqGrid 缓存网格数据

ios - 缺少 APNs 证书。在设置中上传证书

ios - 有谁知道为什么在 ios/cordova 中抛出这个异常?

html - PhoneGap 在设备上存储 HTML 文件

javascript - 如何从 setInterval 函数返回值?

javascript - Redux Thunk 尝试返回 promise

jquery - 使用 jQuery 随机加载 Div

javascript - 使用 .each 循环获取元素属性