简体   繁体   English

如何启用/禁用Google的reCaptcha小部件?

[英]How to enable/disable Google's reCaptcha widget?

Is there a way to programmatically enable/disable Google's reCaptcha widget? 有没有办法以编程方式启用/禁用Google的reCaptcha小部件? The purpose for this would be to prevent a user from clicking the "I'm not a robot" checkbox prematurely. 这样做的目的是防止用户过早单击“我不是机器人”复选框。

I found a solution thanks to this answer . 由于这个答案,我找到了解决方案。

Add this CSS: 添加此CSS:

.disabled-element {
    opacity: 0.65;
    pointer-events: none;
}

Add the disabled-element class to the div containing the reCaptcha element: disabled-element类添加到包含reCaptcha元素的div中:

<script>
  var onloadCallback = function() {
    alert("grecaptcha is ready!");
  };
</script>

<div class="disabled-element" id="captcha"></div>
...
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>

And finally, whenever you're ready to enable the reCaptcha element, remove the class: 最后,每当您准备启用reCaptcha元素时,请删除该类:

$("#captcha").removeClass("disabled-element");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM