验证同一页面上的多个Google重新访问

时间:2017-05-22 02:21:20

标签: javascript recaptcha

我在同一页面上有超过4次google recaptcha。我设法让他们显示,但验证不起作用。



$('#newsletter').on('submit', function(e) {	
      var response = grecaptcha.getResponse();
      if (response.length == 0) {
          e.preventDefault();
          alert("Incorrect captcha code. Please try again.");
          return false;
      } else {
          return true;
      } 
});

<form action="" method="post" id="newsletter">
      <div id="sideRecaptcha" class="g-recaptcha"></div>
      <input type="submit" value="submit" />
</form>
 <script src="https://www.google.com/recaptcha/api.js?onload=reCaptchaCallback&render=explicit&hl=en" async defer></script>
 <script>
      var reCaptchaCallback = function() {
	  var elements = document.getElementsByClassName('g-recaptcha');
	  for (var i = 0; i < elements.length; i++) {
	       var id = elements[i].getAttribute('id');
	       var widgetId = grecaptcha.render(id, {
	       'sitekey' : 'XXXXXXXX',
	       theme' : 'light'
	  });
	       elements[i].setAttribute('cid', widgetId);
	       grecaptcha.reset(widgetId);
	  }
};
</script>
&#13;
&#13;
&#13;

grecaptcha.getResponse()始终返回空。有什么想法吗?

0 个答案:

没有答案