我在头的末尾添加了以下内容

<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>

I can see the recaptcha similar to https://developers.google.com/recaptcha/

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 has a call back option for when the checkbox is checked.

将以下内容添加到表单元素:

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>

然后创建一个回调函数,并编写所需的任何代码.

例子:

function recaptchaCallback() {
    $('#submitBtn').removeAttr('disabled');
};

Jquery相关问答推荐

如何用each替换元素的attr href

点击和touch 事件之间的jQuery冲突解决方法

使用带有 bootstrap 验证的 Ajax 函数时出现问题

jQuery:获取数据属性

ASP .NET MVC 在每个字段级别禁用客户端验证

无法在被动事件侦听器中阻止默认值

如何禁用在div内单击

Codemirror 编辑器在单击之前不会加载内容

如何使用 Javascript/jQuery 确定图像是否已加载?

jQuery 插件:添加回调功能

使用 MVC、C# 和 jQuery 导出为 CSV

jQuery '如果 .change() 或 .keyup()'

是否可以在 beforeunload 弹出窗口中显示自定义消息?

JQuery - 如何根据值 Select 下拉项

滚动 DIV 元素时如何防止页面滚动?

如何在 JavaScript 中的对象数组中查找值?

如何使用 jQuery 删除 cookie?

Select jQuery UI 自动完成后清除表单字段

Fancybox 不适用于 jQuery v1.9.0 [ f.browser 未定义 / 无法读取属性 'msie' ]

detach()、hide() 和 remove() 之间的区别 - jQuery