所以我有这种形式。我想检查用户是否验证了验证码,但有问题。这是检查函数的表单。表单仍然提交,尝试使用e.preventDefault();
<form data-id="embedded_signup:form" id="myForm" class="ctct-custom-form Form" name="embedded_signup" method="POST" action="https://visitor2.constantcontact.com/api/signup" onsubmit="check_if_capcha_is_filled()">
以下是确定doSubmit(验证码)是否已验证的功能。
function check_if_capcha_is_filled(e){
if(doSubmit) return true;
e.preventDefault();
alert('Fill in the capcha!');
return false;
};
但我得到一个错误
Uncaught TypeError: Cannot read property 'preventDefault' of undefined
at check_if_capcha_is_filled
任何指针,我缺少的是什么?谢谢。
'的onsubmit = “返回check_if_capcha_is_filled(事件)”'更好的是,使用'addEventListener'并删除过时的'上*'事件属性 –
地方'e.preventDefault();'在第一行内的函数 –
删除所有内联js和css - 这是不好的做法,导致难以主要的代码和意外的行为也,你正在使用preventDefault,将张贴一个答案 – ThisGuyHasTwoThumbs