重置多个 Google reCAPTCHA [英] Reset Multiple Google reCAPTCHA

查看:80
本文介绍了重置多个 Google reCAPTCHA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个页面上有两个表单,它们都使用 Google reCAPTCHA.

I have two forms on a single page which both use Google reCAPTCHA.

每当我使用 grecaptcha.reset(); 它只会重置第一个实例.

Whenever i use grecaptcha.reset(); it only resets the first instance.

以下 JS 呈现 reCAPTCHA

The following JS renders the reCAPTCHA(s)

var recaptcha1;
var recaptcha2;

var myCallBack = function() {
    //Render the recaptcha1 on the element with ID "recaptcha1"
    recaptcha1 = grecaptcha.render('recaptcha1', {
        'sitekey' : '1234', //Replace this with your Site key
        'theme' : 'light'
    });

    //Render the recaptcha2 on the element with ID "recaptcha2"
    recaptcha2 = grecaptcha.render('recaptcha2', {
        'sitekey' : '1234', //Replace this with your Site key
        'theme' : 'light'
    });
};

如何重置所有实例或针对特定实例.

How can i reset all instances or target a specific instance.

推荐答案

mbejda 的回答几乎正确但不完全正确.

The answer by mbejda is almost correct but not quite.

通过反复试验,我发现你必须这样做:

Through trial and error, I found that you have to do this:

grecaptcha.reset(recaptcha1);
grecaptcha.reset(recaptcha2);

需要明确的是,您必须保存 grecaptcha.render() 的返回值,并将这些变量传递给 reset() 函数.传入验证码的字符串 ID 不起作用.

To be clear, you have to save the return values of grecaptcha.render(), and pass in those vars to the reset() function. Passing in the string ID of the captcha doesn't work.

这篇关于重置多个 Google reCAPTCHA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆