RecaptchaV2启用/禁用提交

时间:2017-06-29 09:27:40

标签: jquery forms recaptcha

我的网页上有一个表单,但是我已经收到了一段时间,所以我添加了Google RecaptchaV2并且它停止了跨度,但是我想禁用“提交”按钮,直到选中Recaptcha并且用户证明是人类。< / p>

RecaptchaV2在Iframe中运行,如何读取元素或属性以禁用提交?

在iframe内部,有一个范围可以在验证后更改内容: 从:

<span id="recaptcha-accessible-status">Recaptcha requires verification</span>

为:

<span id="recaptcha-accessible-status">You are verified</span>

所以阅读我认为可能有可能使用Jquery禁用/启用提交按钮,尝试使用content()来读取但无法访问iframe内容,任何想法?

谢谢!

2 个答案:

答案 0 :(得分:1)

这是答案,这只是在检查时禁用/启用提交按钮:

在一个页面中使用不同的表单但未经过测试,欢迎任何建议/更改。

呼叫:

<div class="g-recaptcha" data-sitekey="KEY-HERE" data-callback="correctCaptcha"></div>
<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl=en"></script>

数据回调=&#34; correctCaptcha&#34; 是主要作品。

JS:

$("form").each(function() {
    $(this).find(':input[type="submit"]').prop('disabled', true);
});
function correctCaptcha() {
    $("form").each(function() {
        $(this).find(':input[type="submit"]').prop('disabled', false);
    });
}

答案 1 :(得分:0)

这就是我最终做的:

  var verifyCallback = function(response) {
    $('.contactForm :input[type="submit"]').prop('disabled', false);
  };

  var onloadCallback = function() {        
    grecaptcha.render('contactForm', {
      'sitekey' : '6LdtYLUaAAAAAFJ1Ltgw2-CmGPd4pyzMt-2PjXVR',
      'callback' : verifyCallback,
      'theme' : 'light'
    });
  };
相关问题