我想验证我的表单,并使用 onsubmit 创建了一个 formValidation 函数,该函数从 js.js 文件调用函数。但是,当我单击“提交”时,出现此错误:
这是必要的表单代码:
<form action="send-email.php" id="callback" class="popup-form" method="post" onsubmit="return validateForm()">
// Form content
</form>
函数代码如下:
function validateForm() {
console.log("hellloooooo this is working");
// var captcha_response = grecaptcha.getResponse();
// if(captcha_response.length === 0)
// {
// // Captcha is not Passed
// console.log("not working");
// return false;
// }
// else
// {
// // Captcha is Passed
// console.log("working");
// return true;
// }
}
脚本标签位于主体标签内,所以它应该可以工作..我哪里出错了?
最佳答案
请在表单中使用输入类型='提交'。它也可以在 java 脚本中运行。
在下面的表单中添加提交输入
<form action="send-email.php" id="callback" class="popup-form" method="post" onsubmit="return validateForm()"><input type="submit">
</form>
并在java脚本中编写如下验证函数
<script type="text/javascript">
function validateForm(){
console.log('ddd');
return false;
}
</script>
关于javascript - 用于表单的 onsubmit 函数即将出现未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49814445/