【发布时间】:2017-04-19 04:52:37
【问题描述】:
我将localstoragedb 用于我的本地数据库,到目前为止,我所做的一切都是正确的。但是在提交表单之一时,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);
});
除了localDb.queryAll 函数之外,所有的 return false 都可以正常工作。
它会提醒我用户名已经存在,但也提交了表单。
return false 看起来有些问题。
我有什么遗漏或做错了吗????
提前致谢…………
【问题讨论】:
标签: javascript jquery local-storage