所以我有這種形式。我想檢查用戶是否驗證了驗證碼,但有問題。這是檢查函數的表單。表單仍然提交,嘗試使用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