Nic*_*nou 2 javascript jquery recaptcha
我有兴趣在用户打勾并验证google recaptcha后立即隐藏resultcaptcha消息.只有第一部分(v.length == 0)有效.否则如果不起作用.你可以在这里查看表格:https://csandreas1.herokuapp.com
if(grecaptcha.getResponse() == 0) // this works
{
$('#resultcaptcha').show();
$('#resultcaptcha').html('<i class="fa fa-exclamation-circle w3-text-red fa-3x" aria-hidden="true"></i> <span class="w3-text-white w3-bold" style="font-size:16px"> Please verify that you are a human</span>');
}
else if(grecaptcha.getResponse() == 1)//this doesn't work
{
$('#resultcaptcha').hide();
$('#resultcaptcha').html('');
}
else{//submit the form}
Run Code Online (Sandbox Code Playgroud)
上面的代码位于表单submit事件处理程序中,只有在单击"提交"(SEND)按钮时才会触发.
要在验证验证码后立即隐藏错误消息,您需要使用验证data-callback码元素(class="g-recaptcha"),顾名思义提供在验证验证码成功验证时执行的回调.这是文档链接.
这是代码应该是什么样子.(我无法使用data-callback属性验证代码,但它确实与grecaptcha.render()方法一起使用)
<script>
function captcha_callback(response) {
if (response.length > 1) {
$('#resultcaptcha').html('');
}
}
</script>
<div class="g-recaptcha" data-sitekey="site_key" data-callback="captcha_callback"><div>
Run Code Online (Sandbox Code Playgroud)
此外,如果您想再次重置验证码,请在成功提交后清除表单,您可以使用:(请参阅文档)
grecaptcha.reset()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1728 次 |
| 最近记录: |