【发布时间】:2015-11-19 23:52:21
【问题描述】:
我正在使用谷歌recaptcha
<label for="template-contactform-botcheck">Botcheck</label>
<div id="recaptcha_sme"></div>
我想验证它是否被选中,是否已被填充,我这样做的方式是通过这段代码(参见下文)
if ($("#recaptcha_sme #recaptcha-anchor").hasClass("recaptcha-checkbox-checked")) {
alert("the captcha has been filled");
} else {
alert("Please fill the captcha!");
}
并且我不打算通过服务器端验证(google recaptcha API 检查),我只想在检查或填写 google recaptcha 时收到通知(使用警报提示)。有什么想法、线索、建议、建议吗?
下面是我完整的表单提交脚本代码(jquery中的提交函数)。
$("#sme_application_dialog form").submit(function(e){
if ($(this).find("#recaptcha_sme #recaptcha-anchor").hasClass("recaptcha-checkbox-checked")) {
alert("the captcha has been filled");
} else {
alert("Please fill the captcha!");
}
e.preventDefault();
});
正如您从上面的参考资料中看到的那样,我只是想检查 id 为“recaptcha-anchor”的元素是否具有“recaptcha-checkbox-checked”类(从 DOM 结构中可以看出)使用chrome dom explorer,该类已添加到ID为“每次检查或填充google recaptcha时recaptcha-anchor的元素中)所以我认为这可能有效,但遗憾的是它不起作用。
PS:假设我有一个 id 为“sme_application_dialog_form”的 div,并且在其中有一个 from 和该表单内部,有 google recaptcha,我有“$(document).ready”。假设一切都已设置并正常工作(除了我正在检查 google recaptcha 的验证已检查或已填写)
【问题讨论】:
-
文档developers.google.com/recaptcha/docs/display#js_api -
grecaptcha.getResponse( opt_widget_id )
标签: javascript jquery recaptcha