google captcha from jquery to vanilla javascript



我创建了这个代码段来验证我的谷歌验证码表单。这是在Jquery中完成的,并希望将其更改为vanilla Javascript。我在网上找到了一些资源,但就是做不好,这是其中之一:https://tobiasahlin.com/blog/move-from-jquery-to-vanilla-javascript/

这是我在Jquery中的工作片段,我将如何将其更改为Vanilla Javascript?

$('.contact-form').on('submit', function(e) {
if(grecaptcha.getResponse() == "") {
e.preventDefault();
$( '.msg-error').text( "Tick to confirm you are human" )}});

我设法解决了它。感谢您的参考@user7290583。

document.querySelector('.contact-form').addEventListener('submit', (e) => {
if(grecaptcha.getResponse() == "") {
e.preventDefault();
errorMsg = document.getElementById("msg-error");
errorMsg.textContent = "Please tick box to confirm you are not a robot";
}});

最新更新