javascript Google ReCAPTCHA 回调函数不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31395162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 13:43:57  来源:igfitidea点击:

Google ReCAPTCHA callback function not working

javascripthtmlrecaptcha

提问by Just some guy

I use Google's reCAPTCHA on my website and I'm having problems getting it to call a callback function. After a user has successfully passed the captcha I want to call a function. I use a div with these attributes to render the captcha:

我在我的网站上使用了 Google 的 reCAPTCHA,但在让它调用回调函数时遇到了问题。用户成功通过验证码后,我想调用一个函数。我使用具有这些属性的 div 来呈现验证码:

class='g-recaptcha' data-sitekey='keyhere' data-callback='alert(1);'

However, I can't get the alert(1);to trigger, nothing happens when I fill out the captcha. Everything else about the captcha works fine, I just can't get it to call the function. What could I be doing wrong?

但是,我无法alert(1);触发,当我填写验证码时没有任何反应。关于验证码的其他一切工作正常,我只是无法让它调用该函数。我可能做错了什么?

回答by Joe Enos

I haven't used it, so I don't know if this will help, but looking at the few examples online that I can find, it looks like data-callbackshould be a function name, not the script body:

我没有使用过,所以不知道这是否有帮助,但是查看我可以找到的几个在线示例,它看起来data-callback应该是函数名称,而不是脚本主体:

class='g-recaptcha' data-callback='doSomething'

function doSomething() { alert(1); }