Javascript 返回false不在localstoragedb中工作
我正在使用我的本地数据库,到目前为止,我所做的一切都是正确的。但是在提交一个表单时,returnfalse并没有停止提交表单。 这是代码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;
$("#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时出现了一些问题。
是我错过了什么还是做错了什么?????
提前感谢………我在循环中犯了一个错误,因为它继续在每一行中搜索特定的值,并在找不到的地方插入它。这是正确的代码