2015-07-10 135 views
2

我在單個頁面上使用Google reCAPTCHA的兩種表單。重置多個Google reCAPTCHA

每當我使用grecaptcha.reset();它只會重置第一個實例。

下JS渲染驗證碼(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' 
    }); 
}; 

如何重置所有實例或針對特定的實例。

回答

6

通過mbejda的答案几乎是正確的,但不完全是。

經過反覆試驗,我發現,你必須這樣做:

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

要清楚,你已經保存grecaptcha.render()的返回值,並通過這些增值經銷商向reset()函數。傳入驗證碼的字符串ID不起作用。