如何检查js用户已选中Google recaptcha中的复选框? [英] How to check in js that user has checked the checkbox in Google recaptcha?

查看:983
本文介绍了如何检查js用户已选中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>

我可以看到recaptcha类似https://developers.google.com/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 have 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');
};

这篇关于如何检查js用户已选中Google recaptcha中的复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆