如何检查用户已选中 Google recaptcha 中的复选框的 js? [英] How to check in js that user has checked the checkbox in Google recaptcha?
问题描述
我在头部结束前添加了以下内容
I have added the following before end of head
<script src='https://www.google.com/recaptcha/api.js'></script>
我在表格结束前添加了这个
I have added this before end of form
<div class="g-recaptcha" data-sitekey="== xxxxxx =="></div>
我可以看到类似于https://developers.google.com/recaptcha/的recaptcha
I can see the recaptcha similar to https://developers.google.com/recaptcha/
然而,当用户在没有选中复选框的情况下按下数据时,数据被提交.我是否需要添加任何其他代码来检查用户是否按下了复选框?希望在 js 中?
HOwever, when user presses data without checking the checkbox, the data is submitted. Is there any other code I need to add to check if user has pressed the checkbox? Hopefully in js?
推荐答案
Google 有一个回拨选项,用于在复选框被选中时.
Google has a call back option for when the checkbox is checked.
将此添加到您的表单元素:
Add this to your form element:
data-callback="XXX"
示例:
<div class="g-recaptcha" data-callback="recaptchaCallback" data-sitekey="== xxxxxx =="></div>
以及提交按钮的禁用属性.
And a disable attribute to your submit button.
示例:
<button id="submitBtn" disabled>Submit</button>
然后创建一个回调函数并编写您需要的任何代码.
Then a create a callback function and write whatever code you need.
示例:
function recaptchaCallback() {
$('#submitBtn').removeAttr('disabled');
};
这篇关于如何检查用户已选中 Google recaptcha 中的复选框的 js?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!