我在一个页面上有两个表单,都使用Google reCAPTCHA。
[每当我使用grecaptcha.reset();
时,它只会重置第一个实例。
以下JS呈现reCAPTCHA
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'
});
};
如何重置所有实例或定位到特定实例。
mbejda的回答几乎是正确的,但不太正确。
通过反复试验,我发现您必须这样做:
grecaptcha.reset(recaptcha1);
grecaptcha.reset(recaptcha2);
要清楚,您必须保存grecaptcha.render()的返回值,并将这些变量传递给reset()函数。传递验证码的字符串ID无效。
根据googles文档。https://developers.google.com/recaptcha/docs/display#js_param您应该能够将验证码ID传递给reset方法。grecaptcha.reset(widgetId);
那么您就可以做:
grecaptcha.reset( “recaptcha1”);grecaptcha.reset( “recaptcha2”);
grecaptcha.reset(0);
grecaptcha.reset(1);