Javascript Google reCAPTCHA 数据回调不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35614606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Google reCAPTCHA data-callback not working
提问by roshambo
I have built a email newsletter signup form which posts into mailchimp from my website. I have Google reCAPTCHA added to the form and have a data-callback to enable the submit button as it is initially disabled. This was working fine in all browsers last night and did tests with success & signed off on it..and went home. I got in this morning and found the subscribe button will not enable / data-callback does not work? Strange..
我已经建立了一个电子邮件通讯注册表格,可以从我的网站发布到 mailchimp。我在表单中添加了 Google reCAPTCHA,并有一个数据回调来启用提交按钮,因为它最初被禁用。昨晚在所有浏览器中都运行良好,并成功进行了测试并签署了它......然后回家了。我今天早上起来,发现订阅按钮无法启用/数据回调不起作用?奇怪的..
Callback
打回来
<div class="g-recaptcha" data-callback="recaptcha_callback" data-sitekey="xxxxx"></div>
Input button at bottom of form
表单底部的输入按钮
<input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button" disabled>
Scripts
脚本
<script src='https://www.google.com/recaptcha/api.js'></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
function recaptcha_callback(){
alert("callback working");
$('.button').prop("disabled", false);
}
)};
</script>
回答by m-albert
Change your script to...
将您的脚本更改为...
<script type="text/javascript">
function recaptcha_callback(){
alert("callback working");
$('.button').prop("disabled", false);
}
</script>
By placing your function inside the document.ready
event, it is not in the global scope and therefore unreachable by the captcha control.
通过将您的函数放在document.ready
事件中,它不在全局范围内,因此验证码控件无法访问。