Rya*_*ton 4 javascript jquery recaptcha
我在一个页面上有两个表单,都使用Google reCAPTCHA.
每当我使用grecaptcha.reset();
它时,只会重置第一个实例.
以下JS呈现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'
});
};
Run Code Online (Sandbox Code Playgroud)
如何重置所有实例或定位特定实例.
mbejda的答案几乎是正确的,但并不完全正确.
通过反复试验,我发现你必须这样做:
grecaptcha.reset(recaptcha1);
grecaptcha.reset(recaptcha2);
Run Code Online (Sandbox Code Playgroud)
要清楚,您必须保存grecaptcha.render()的返回值,并将这些变量传递给reset()函数.传入验证码的字符串ID不起作用.
根据这里的谷歌文档。
https://developers.google.com/recaptcha/docs/display#js_param
您应该能够将验证码 Id 传递到重置方法中。
grecaptcha.reset(widgetId);
那么你可以这样做:
grecaptcha.reset("recaptcha1"); grecaptcha.reset("recaptcha2");