如何在同一页面中使用多个google recaptcha?

时间:2018-04-24 03:04:42

标签: javascript recaptcha

我尝试了2个代码但没有工作,我该怎么办?

当我第一次重新接收成功然后点击test first recaptcha时,它会警告不为零(没关系),然后点击test second captcha为什么它没有提醒也是零。我怎样才能在同一页面上使用multiplr google recaptcha?



<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<script src="https://www.google.com/recaptcha/api.js?onload=CaptchaCallback&render=explicit" async defer></script>
<script type="text/javascript">
    var CaptchaCallback = function() {
        grecaptcha.render('recaptcha_1', {'sitekey' : 'MY-sitekey-code'});
        grecaptcha.render('recaptcha_2', {'sitekey' : 'MY-sitekey-code'});
    };
</script>

<div id="recaptcha_1" class="g-recaptcha" data-size="compact" data-type="image"></div>
<br>
<div onclick="test_1_fn()">test first recaptcha</div>
<script>
function test_1_fn()
{
	var $captcha = $( '#recaptcha_1' ),
	response = grecaptcha.getResponse();
	alert(response.length);
}
</script>

<br>

<div id="recaptcha_2" class="g-recaptcha" data-size="compact" data-type="image"></div>
<br>
<div onclick="test_2_fn()">test</div>
<script>
function test_2_fn()
{
	var $captcha = $( '#recaptcha_2' ),
	response = grecaptcha.getResponse();
	alert(response.length);
}
</script>
&#13;
&#13;
&#13;

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<script src='https://www.google.com/recaptcha/api.js'></script>
<div id="recaptcha_1" class="g-recaptcha" data-size="compact" data-type="image" data-sitekey="MY-sitekey-code"></div>
<br>
<div onclick="test_1_fn()">test</div>
<script>
function test_1_fn()
{
	var $captcha = $( '#recaptcha_1' ),
	response = grecaptcha.getResponse();
	alert(response.length);
}
</script>

<br>

<div id="recaptcha_2" class="g-recaptcha" data-size="compact" data-type="image" data-sitekey="MY-sitekey-code"></div>
<br>
<div onclick="test_2_fn()">test second captcha</div>
<script>
function test_2_fn()
{
	var $captcha = $( '#recaptcha_2' ),
	response = grecaptcha.getResponse();
	alert(response.length);
}
</script>
&#13;
&#13;
&#13;

0 个答案:

没有答案