javascript - 使用带有 else 的 if 语句来验证表单并在表单有效时重定向到新页面
问题描述
嗨,我有此代码来验证有效的表单,但如果表单有效,它不执行 else 语句并直接到页面
function printpage() {
if (!mandatoryText(document.getElementById('FIRSTNAME_FIELD'), 'First name')) return false;
if (!mandatoryText(document.getElementById('LASTNAME_FIELD'), 'Last name')) return false;
if (!mandatoryText(document.getElementById('ZIP_CODE_FIELD'), 'Post code')) return false;
if (!mandatoryText(document.getElementById('EMAIL_FIELD'), 'Email')) return false;
if (!isEmail(document.getElementById('EMAIL_FIELD'))) return false;
if (!isDateOK(document.getElementById('LAST_SHOWROOM_VISIT_FIELD').value)) return false;
if (document.getElementById('LAST_SHOWROOM_VISIT_FIELD').value != '') modifyDateFormat(document.getElementById('LAST_SHOWROOM_VISIT_FIELD'));
document.getElementById('emvForm').submit();
if (document.getElementById('LAST_SHOWROOM_VISIT_FIELD').value != '') modifyDateFormat(document.getElementById('LAST_SHOWROOM_VISIT_FIELD'));
else {
return true;
var p1 = document.getElementById('SELECTED_PRODUCT_1_FIELD').value;
window.location.href = "summary.html?" + "p1" + "=" + p1;
}
}
解决方案
推荐阅读
- java - 使用 JSch 从 Java 连接到 SSH 服务器时出现“JSchException:拒绝 HostKey”
- java - 如何从 Java Swing Timer 计算经过的时间
- c# - 如何对返回 ToList 的操作进行单元测试
- c++ - 对静态函数 c++ 的未定义引用
- c++ - int 数组但索引是字符?
- macos - 如何从目录中删除或修剪 $PATH 变量的一部分:macOS zsh
- ios - Flutter Cupertino appbar 隐藏屏幕空间
- c++ - 在 C++ 中的向量中查找() stl
- c - 使用 C 中的字符串通过引用传递
- swift - SwiftUI中多个异步api请求完成后如何调用函数?