我有两个相同形式的验证码。一个用于提交,另一个用于表单提交后将打开的模式。所以我在阅读了这里的许多答案后渲染它。现在它在mozilla上运行良好,但在 chrome 中给出了参考错误。
我的谷歌 API 是:
<script src='https://www.google.com/recaptcha/api.js'></script>
然后我的代码在java脚本中呈现这个:
$('.g-recaptcha').each(function(index, el) {
widgetId = grecaptcha.render(el, {'sitekey' : 'My-SITE-KEY'});
});
我的 html 是这样读的
<div id="user_recaptcha" class="reCaptcha">
<div id="e_Captcha" class="g-recaptcha" data-sitekey="<?php echo SITE_KEY; ?>" data-callback="recaptchaCallbackEvent"></div>
</div>
我widgetId
在我的 js 的顶部声明。
Recaptcha 有一个 onload 回调,一旦加载 recaptcha 就会运行。将您的代码放在该回调函数中。
https://developers.google.com/recaptcha/docs/display
//call this function in your js
function onloadCallback() {
$('.g-recaptcha').each(function(index, el) {
widgetId = grecaptcha.render(el, {'sitekey' : 'My-SITE-KEY'});
});
}
//load this script before your js is loading
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"></script>
//your html is absolutely fine.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句