Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 检查google recaptcha是否已选中或已填充_Javascript_Jquery_Recaptcha - Fatal编程技术网

Javascript 检查google recaptcha是否已选中或已填充

Javascript 检查google recaptcha是否已选中或已填充,javascript,jquery,recaptcha,Javascript,Jquery,Recaptcha,我正在使用google recaptcha <label for="template-contactform-botcheck">Botcheck</label> <div id="recaptcha_sme"></div> 我不打算通过服务器端验证(GoogleRecaptchaAPI检查),我只想在GoogleRecaptcha被检查或填充时得到通知(使用警报提示)。有什么想法、线索、建议、建议吗 下面是我完整的表单提交脚本代码(jquery

我正在使用google recaptcha

<label for="template-contactform-botcheck">Botcheck</label>
<div id="recaptcha_sme"></div>
我不打算通过服务器端验证(GoogleRecaptchaAPI检查),我只想在GoogleRecaptcha被检查或填充时得到通知(使用警报提示)。有什么想法、线索、建议、建议吗

下面是我完整的表单提交脚本代码(jquery中的提交函数)

正如您从上面的引用中所看到的,我只是想检查id为“recaptcha锚定”的元素是否有一个“recaptcha复选框已选中”的类(正如我从使用chrome DOM explorer的DOM结构中看到的,该类已添加到id为的元素中)“每次检查或填充google recaptcha时,recaptcha锚定)因此我认为这可能会起作用,但不幸的是,它不起作用


PS:假设我有一个id为“sme\u应用程序\u对话框\u表单”的div,在它里面有一个from,在这个表单里面有google recaptcha,我有“$(document).ready”。假设一切都已设置并正常工作(除了我正在检查google recaptcha的验证已被检查或已被填充)

您可以通过获取响应值来验证回调函数是否为空

回调函数

function submit(){ 
     var response = grecaptcha`.`getResponse();
     if(response != '0'){
           //captcha validated and got response code
           alert("the captcha has been filled");
     }else{
           //not validated or not clicked
           alert("Please fill the captcha!");
     }
}

它会起作用。

数据回调添加到您的
recompthca
div:

<div class="g-recaptcha" data-sitekey="***" data-callback="recaptchaCallback"></div>

您现在可以在OnSubmit()函数上使用recaptchachecked。

文档-
grecaptcha.getResponse(opt_widget_id)
看看这篇文章:三星代表什么可能重复?DIV需要那个特定的类名吗?它是V2:。***是站点密钥,是的,需要div结构。
function submit(){ 
     var response = grecaptcha`.`getResponse();
     if(response != '0'){
           //captcha validated and got response code
           alert("the captcha has been filled");
     }else{
           //not validated or not clicked
           alert("Please fill the captcha!");
     }
}
<div class="g-recaptcha" data-sitekey="***" data-callback="recaptchaCallback"></div>
var recaptchachecked;
function recaptchaCallback() {
    //If we managed to get into this function it means that the user checked the checkbox.
    recaptchachecked = true;
}