JavaScript 并不是我的强项。我已经在后端使用了用于验证码的 php,但我希望能够使用 JS 验证表单,以防止用户在验证码尚未完成时发送表单。
这是 hcaptca 网站提供的示例: https://medium.com/@hCaptcha/using-hcaptcha-with-php-fc31884aa9ea
这是他们作为示例给出的 JS 代码。
$("form").submit(function(event) {
var hcaptchaVal = $('[name=h-captcha-response]').value;
if (hcaptchaVal === "") {
event.preventDefault();
alert("Please complete the hCaptcha");
}
});
Run Code Online (Sandbox Code Playgroud)
我不是 100% 确定,但这似乎是 Jquery,而我的网站不使用 Jquery。所以我需要一个普通的 JS 解决方案。