Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 返回false不在localstoragedb中工作_Javascript_Jquery_Local Storage - Fatal编程技术网

Javascript 返回false不在localstoragedb中工作

Javascript 返回false不在localstoragedb中工作,javascript,jquery,local-storage,Javascript,Jquery,Local Storage,我正在使用我的本地数据库,到目前为止,我所做的一切都是正确的。但是在提交一个表单时,returnfalse并没有停止提交表单。 这是代码 $("#registration").on("submit", function(e) { e.preventDefault(); if ($('#username').val() === '') { $('#username').parent().addClass('error'); return false;

我正在使用我的本地数据库,到目前为止,我所做的一切都是正确的。但是在提交一个表单时,returnfalse并没有停止提交表单。 这是代码

$("#registration").on("submit", function(e) {
    e.preventDefault();
    if ($('#username').val() === '') {
        $('#username').parent().addClass('error');
        return false;
    };
    if ($('#password').val() === '') {
        $('#password').parent().addClass('error');
        return false;
    };
    if ($('#mobile').val() === '') {
        $('#mobile').parent().addClass('error');
        return false;
    };

    localDb.queryAll("UserInfo");
    localDb.queryAll("UserInfo", {
        query: function(row) {
            if (row.username === $('#username').val()) {
                alert("username already existed");
                return false;
            }

        }

    });


    localDb.insert("UserInfo", {
        username: $('#username').val(),
        password: $('#password').val(),
        Mobile: $("#mobile").val()
    });
    localDb.commit();
    $(".message").show();
    setTimeout(function() {
        window.location.replace("login.html");
    }, 2000);

});
$("#registration").on("submit", function(e) {
    e.preventDefault();
    if ($('#username').val() === '') {
        $('#username').parent().addClass('error');
        return false;
    };
    if ($('#password').val() === '') {
        $('#password').parent().addClass('error');
        return false;
    };
    if ($('#mobile').val() === '') {
        $('#mobile').parent().addClass('error');
        return false;
    };

    localDb.queryAll("UserInfo");
    localDb.queryAll("UserInfo", {
        query: function(row) {
            if (row.username === $('#username').val()) {
                alert("username already existed");
                return false;
            }

        }

    });


    localDb.insert("UserInfo", {
        username: $('#username').val(),
        password: $('#password').val(),
        Mobile: $("#mobile").val()
    });
    localDb.commit();
    $(".message").show();
    setTimeout(function() {
        window.location.replace("login.html");
    }, 2000);

});
除了在
localDb.queryAll
函数中之外,所有返回的false都正常工作。 它会提醒我用户名已经存在,但也提交了表单。 看来
返回false时出现了一些问题。
是我错过了什么还是做错了什么?????

提前感谢………

我在循环中犯了一个错误,因为它继续在每一行中搜索特定的值,并在找不到的地方插入它。这是正确的代码