所以我有2个函数,一个是异步函数,基本上是HTTP Post Request,另一个是表单验证。我希望 POST 请求函数仅在表单验证函数返回 true 时才触发。表单验证如下所示:
regForm.addEventListener('submit', function(event){
if (checkInputs()) {
// trigger post request function
}
})
function checkInputs() {
const usernameValue = form.username.value.trim();
const passwordValue = form.password.value.trim();
const emailValue = form.email.value.trim();
if (usernameValue === '') {
// trigger another function that handles errors
setError(form.username, 'Can\'t be blank');
} else {
// triggers function that handles success(color change, etc.)
setSuccess(form.username);
}
if (passwordValue=== '') {
// trigger another function that handles errors
setError(form.password, 'Can\'t be blank');
} else {
// triggers function that handles success(color change, etc.)
setSuccess(form.password);
}
}
但这似乎不起作用,它不会触发POST请求功能。
狐的传说
守候你守候我
相关分类