我在页面上有多个谷歌验证码。代码:
<script>
var qqqq =function(captcha_response){
console.log('?')
}
var CaptchaCallback = function(){
$('.g-recaptcha').each(function(index, el) {
grecaptcha.render(el, {'sitekey' : '{{ recaptcha_key}}', 'callback': 'qqqq', 'theme': 'dark'});
});
};
</script>
<script src='https://www.google.com/recaptcha/api.js?onload=CaptchaCallback&render=explicit' async defer></script>
在页面上有几个用于 reCAPTCHA 的 block :
<div class="g-recaptcha"></div>
所有 reCAPTCHA 的渲染都很好,都带有深色主题,都进行验证工作,但callback
函数不会被调用。
当我尝试使用带有数据回调属性的单一 reCAPTCHA 时,它运行良好。
最佳答案
我遇到了同样的问题。再次检查文档后,我发现了我的问题。尝试删除函数名称两边的单引号。 像这样:
<script>
var qqqq =function(captcha_response){
console.log('?')
}
var CaptchaCallback = function(){
$('.g-recaptcha').each(function(index, el) {
grecaptcha.render(el, {'sitekey' : '{{ recaptcha_key}}', 'callback': qqqq });
});
};
</script>
也许这对其他人也有帮助:)
关于javascript - Google recaptcha 回调不适用于多个 reCAPTCHA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41389467/